I've made a sword and I have this weird problem were it will do damage to a humanoid when testing my place in studio, but when I start up a server it will only deal damage once and then it stops. Is there some kind of client side v.s server side thing going on? Please Help, thank you.
Damage code located in the Blade of the model:
wait(0.01)
CanDamage = true
plr = game.Players.LocalPlayer
script.Parent.Touched:connect(function(part)
local hum = part.Parent:FindFirstChild("Humanoid")
if hum then
if CanDamage == true and script.Parent.Parent.Swinging.Value == true then
CanDamage = false
hum:TakeDamage(10)
plr.swordlvl.Value = plr.swordlvl.Value + 2
wait(0.8)
CanDamage = true
end
end
end)

4 comments
Thank you for responding, I replaced the code with what you edited and got an error: "TakeDamage is not a valid member of Part", I'm not sure what is happening...is it not detecting the humanoid?
I fixed my mistake, It should work now
Good news, the sword does damage again. Bad news, I'm back to the same problem I had before. When I play in studio mode it does damage, but when I open a server and play it only does damage once and then stops...I don't even know what to do anymore, I've tried multiple tests and it still won't work...thanks for trying to help.
Problem Fixed!! Moved all the code to a local script and it worked!! So glad I can finally continue working on my game