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

Why does my sword deal deal damage when testing in studio mode, but not in a server?

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)

1 answer

✓ Accepted answer

You wrote the script Inefficiently, and I can see why

wait(0.01)
CanDamage = true
plr = game.Players.LocalPlayer

script.Parent.Touched:connect(function(hum) -- Changed "part" to "hum"
    -- local hum = part.Parent:FindFirstChild("Humanoid") Delete this
    if hum and hum.Parent:FindFirstChild("Humanoid") then -- "hum" is the Player who touched the part/Sword.
            if CanDamage == true and script.Parent.Parent.Swinging.Value == true then
                CanDamage = false
                hum.Parent.Humanoid:TakeDamage(10) -- I forgot to add the "Parent.Humanoid" part after "hum"
                plr.swordlvl.Value = plr.swordlvl.Value + 2
                wait(0.8)
                CanDamage = true
            end
        end

end)

4 comments

0

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?

0

I fixed my mistake, It should work now

0

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.

0

Problem Fixed!! Moved all the code to a local script and it worked!! So glad I can finally continue working on my game

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