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

Sword Only Kills Player On Client?

I have a server script with this code:

local candamage = true
script.Parent.Activated:Connect(function()
    script.Parent.Blade.Touched:Connect(function(hit)
        local Char = hit:FindFirstAncestorOfClass("Model")
            if Char then
            local Hum = Char:FindFirstChild("Humanoid")
                   if hum then
		 if candamage == true then
                    candamage = false
                    Hum:TakeDamage(15)
                    wait(0.6)
                    candamage = true
          	 end
	 end
        end
    end)
end)

But it only kills the player on the client like its inside a local script

1 answer

✓ Accepted answer

Try this

local SP = script.Parent
local debounce = true
local damage = 20
SP.Activated:Connect(function()
	SP.Touched:Connect(function(hit)
		local EnemyHumanoid = hit.Parent:WaitForChild("Humanoid", 3)
		if EnemyHumanoid and debounce then
			debounce = false
			EnemyHumanoid:TakeDamage(damage)	
			wait(0.5)
			debounce = true
		end
	end)
end)

10 comments

0

it worked a little but then the same bug happend

0

Hm, weird i tested it out on a local server. Worked for client and server. How are you testing it?

0

have a friend join the place itself

0

and the output says "Touched is not a valid member of Tool"

0

Ok, so do this. Hav everything but the damage part. Try a Remote Event, that when fired by a local script, the server sciprt in SSS, find the player and damage them.

0

nvm fixed it

0

how'd you fix?

0

sorry i just set the touch as the blade and it was fixed

0

can you specify? Just want to edit the code correctly.

0

Sp.Blade.Touched:Connect(function(hit) i set the touch detector to that line

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