Remote Events when listening from the server(i.e When you do OnServerEvent:Connect provides you with a reference to the player as the first parameter. The character is bound to the player so what you can do is
Death.OnServerEvent:Connect(function(player, ...)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
humanoid.Health = humanoid.Health - 999
end
Anything else you want to provide to this event you can put in place of the ... however you need to send that stuff through the even fire which would look like this
Its a troll face mask. When activated, it doesn’t kill you immedietly, you have to wear it for 3 seconds, then it will kill you.
Another issue is that every time I try to get the character or player, I always do tool.Parent, which didn’t work. It always says that character or humanoid or player is nil.
local tool = script.Parent
local event = tool:WaitForChild("Death")
tool.Activated:Connect(function(player, ...)
event:FireServer()
end)
and this is my server script. Which both are in a tool. :
local tool = script.Parent
local death = tool:WaitForChild("Death")
death.OnServerEvent:Connect(function(player, character)
local character = player.Character or player.CharacterAdded:Wait()
local health = character:FindFirstChild("Humanoid").Health
health = health - 50
end)
local tool = script.Parent
local death = tool:WaitForChild("Death")
death.OnServerEvent:Connect(function(player, character)
character = tool.Parent
character.Humanoid.Health = character.Humanoid.Health - 50
end)
Remove the character variable, and instead do player.Character to do it. player.Character is a better strategy than grabbing the object seen, so the exploiters cannot make kill scripts outta em.
Instead of doing FindFirstChild, do WaitForChild.
Also, if you’re going to do Player.Character, then you can check with if statements if player.Character exists.
It’s better to by the way, damage the player without remote events if you’re planning on some sort of “poison apple”
I know this just got solved, but there’s some issues atleast you can do or something.
when firing the server from the client, it will return to script the array of the user, not the variable you want to add at the first
so putting this local parent = partThatCouldKillYou.Parent will just give you path to game.Players
Hello @squaredsnow,
im back from class but i see that it has been solved so this will be an extended for other user who need it when killing the user when activating the tool.but this is what i created.:
-- server
local death = script.Parent.death
death.OnServerEvent:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid:TakeDamage(humanoid.MaxHealth)
end
end
end)
-- client
script.Parent.Activated:Connect(function()
script.Parent.death:FireServer()
end)
If you want to kill (respawn) the player’s character then you can simply use Player:LoadCharacter() without needing to index the player’s character property and then fetch/reference the character’s humanoid instance.