Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you please help me with this Script issue that is causing me frustration?

Asked by 6 years ago
Edited 6 years ago

what happened was, i made a sword with animation and it was successful apart from the damage script, It keeps putting a error up that makes no sense and I cant unpatch it.

--Players.KOOLKILLER786.Backpack.ClassicSword.Damage:10: attempt to index local 'hum' (a nil value)--

--Script--

local CanAttack = script.Parent.CanAttack

script.Parent.Handle.Touched:Connect(function(hit)

local hum = hit.Parent:FindFirstChild("Humanoid")

if CanAttack.Value == true then wait()

CanAttack.Value = false

hum:TakeDamage(20)
end end)

--

Please Help me

0
Please use the "Lua" when asking a question. Jo_Bot 67 — 6y

1 answer

Log in to vote
0
Answered by
Kegani 31
6 years ago

Hello

Maybe you should add

local CanAttack = script.Parent.CanAttack

script.Parent.Handle.Touched:Connect(function(hit) 
local hum = hit.Parent:FindFirstChild("Humanoid") 
if hum ~= nil then
if CanAttack.Value == true then wait() 
CanAttack.Value = false hum:TakeDamage(20)
end
end 
end)

"if hum ~= nil"

It will verify if the humanoid is there

0
oh, thanks KOOLKILLER786 -5 — 6y
0
But that value dont return to normal KOOLKILLER786 -5 — 6y
Ad

Answer this question