Hi, I think I mentioned this before, but I am making a rooms recreation on Roblox. In the original, when a player dies, they vanish from the Escape Menu and the tab playerlist, I wrote some code to do it and it seems to work on one client, but not on the other. The player still respawns but their camera is locked and they can’t move on the other player’s side.
here’s the code i wrote for it, it’s in a local script inside of StarterPlayerScripts
game:GetService("RunService").RenderStepped:Connect(function()
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
player:Destroy()
end)
end)
any ideas? am I doing something wrong?
Any help is appreciated, thank you in advance
Well the first thing I noticed is that for ever renderstep you connect a new function to humanoid.Died. This can cause a ton of lag and possible errors.
What you could do would be to tell the server fire all clients with a player in the first parameter, and each client would locally call destroy() on that player. You could also just make your own playerlist, which would probably be a lot better.
Edit: In script executer games I have seen people removing themselves from the leaderboard, and I have absolutely no idea how they do it. You might be able to find a server side script that hides a player.
In a playeradded event you can get the humanoid of the player’s character and connect a humanoid.Died event, then when that player dies use :FireAllClients() on a remote event with the player that died as the parameter, then in the OnClientEvent the player can locally delete the player from the parameter
Here’s a working version of a script, obv no anti exploit:
Localscript
local rs = game:GetService("ReplicatedStorage")
local remote = rs.RemovePlayer
--there should be a remote in replicated storage called RemovePlayer
--the following function will trigger when the player dies
function onDeath()
remote:FireServer()
end
--this funcion removesthe player
remote.OnClientEvent:Connect(function(plr)
if plr then
if plr~=game:GetService("Players").LocalPlayer then --this line stops the player who died from removing themselves.
if plr.ClassName == "Player" then
plr:Destroy()
end
end
end
end)
--you can put any form of checking for player death
local c = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.Character:Wait()
local hum = c:WaitForChild("Humanoid")
hum.Died:Connect(onDeath)
Serverscript
local rs = game:GetService("ReplicatedStorage")
local remote = rs.RemovePlayer
remote.OnServerEvent:Connect(function(plr)
if plr then
if plr.ClassName == "Player" then
remote:FireAllClients(plr)
end
end
end)