Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

0

Please use the "Lua" when asking a question.

1 answer

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

2 comments

0

oh, thanks

0

But that value dont return to normal

This discussion is preserved as it was. New answers, comments, and votes are closed.