The weapon does not kill the player

Hello everybody today when I did, Weapon kills instantly, but the problem is the client and the second player see another
script:

script.Parent.Hitbox.Touched:Connect(function(Hit)
	local check = Hit.Parent.Name
local PlayerS = game.Players
local Player = PlayerS:FindFirstChild(check)
local PlayerHealth = Player.Character.Humanoid.Health
	if script.Parent.MouseClick.Value == true then
		if Player.Character.Humanoid then
			if Player.Character.HumanoidRootPart then
				Player.Character.Humanoid.Health = PlayerHealth-100
			end
		end
	end
end)

and video

1 Like

This will be because your ‘kill’ script is being controlled on the Client (via LocalScript) - not the Server.

You need the client to tell the server that you’ve hit someone, then get the server to kill them.

1 Like

The problem behind this is the usage of LocalScript. LocalScripts do not replicate to server and thus, the one client will only see the other client dead, while the other client is actually alive.

Try a conversion to a normal server script. LocalScript should communicate with the server using RemoteFunction or similar for optimal sync of input.

That’s just that I did not understand what the Remote Function
https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

Remote functions are simply objects where either server or client invoke, causing the thread from the invocation to yield until result is returned.

I understand thanks for the information

1 Like

Basically on that line put an event :fireserver(Player) and put the original line in the event script

Ok so I remember someone talking about :TakeDamage() which actually will replicate to the server even if used in a local script, I might be wrong though. Let’s try it maybe it works.

if Player.Character.HumanoidRootPart then
	Player.Character.Humanoid:TakeDamage(100)
end

That wouldn’t be possible, due to the fact if it was exploitable, exploiters would spam this as a kill all execution, damaging all players across the server.

1 Like

That doesn’t work, but I am doing what Operatik said.

Ok then my information was wrong really sorry!