这个“CRIT”广告牌 GUI 无法工作,如何修复它?

问题描述 投票:0回答:1

所以输出显示 Workspace.Knife.Script:58: attempts to index nil with 'Character'

这是显示的代码

local player = game.Players.LocalPlayer
local Character = player.Character
local hum = player.Character:FindFirstChild("Humanoid")
                    
local gui = Instance.new("BillboardGui")

gui.Parent = hum.Parent.Head
gui.Adornee = hum.Parent.Head
gui.Size = UDim2.new(0, 200, 0, 50)
gui.StudsOffset = Vector3.new(0, 2, 0)
                    
local text = Instance.new("TextLabel")
                    
text.Parent = gui
text.Size = UDim2.new(1, 0, 1, 0)
text.BackgroundTransparency = 1
text.TextColor3 = Color3.fromRGB(223, 204, 0)
text.TextScaled = true
text.Text = "1.75x"

wait(1)
                    
gui:Destroy()
                    
hit.Parent.Humanoid:TakeDamage(8*1.75)
hitboxActivated = false

我该怎么做?

lua roblox
1个回答
0
投票

从错误消息中,它显示

Workspace.Knife.Script
,这表明您正在使用 Script 而不是 LocalScript(除非您将 LocalScript 的名称更改为 Script)。

在您的代码中,您使用

local player = game.Players.LocalPlayer
,但如果您不在 LocalScript 中,则无法获取 LocalPlayer,因为 Script 在服务器上运行并且没有 LocalPlayer。

考虑将脚本的类从 Script 更改为 LocalScript,以便可以使用 LocalPlayer。

© www.soinside.com 2019 - 2024. All rights reserved.