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

Sword Kills Player But Only On That Client?

i have a local script for animations and a server script for damage yet the client that "died" is still alive

server script:

script.Parent.Activated:Connect(function()
			script.Parent.Blade.Touched:Connect(function(hit)
			local Humanoid = hit.Parent.Humanoid
			Humanoid.Health = Humanoid.Health - 0.1
		end)
end)

local script:

local debounce = true

script.Parent.Activated:Connect(function()
	local Swing1 = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Swing1)
	if debounce == true then
		debounce = false
		Swing1:Play()
		game.Players.LocalPlayer.leaderstats.Strength.Value = game.Players.LocalPlayer.leaderstats.Strength.Value + 2
		game.Players.LocalPlayer.leaderstats.Coins.Value = game.Players.LocalPlayer.leaderstats.Coins.Value + math.random(1,5)
		wait(0.6)
		debounce = true
	end
	
	
end)

1 comment

0

That server script is gonna error like mad, any time the sword touches something whose parent doesn't have a Humanoid as child (anything in world, character accessory Handle parts, etc). It will try to set Health on a nil reference.

1 answer

✓ Accepted answer

That server script is gonna error a LOT. You need to clearly make sure that hit is indeed the part of a character. Here.

local candamage = true
script.Parent.Activated:Connect(function()
	script.Parent.Blade.Touched:Connect(function(hit)
		local Char = hit:FindFirstAncestorOfClass("Model")
			if Char then
			Hum = Char:FindFIrstChild("Humanoid")
				if Hum them
					if candamage == true then
					candamage = false
					Hum.Health = Hum.Health - 0.1
					wait(1)
					candamage = true
				end
			end
		end
	end)
end)

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