Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to detect when player leaves server?

Asked by 2 years ago
Edited 2 years ago

Hello! I need a script where when a player leaves a part gets destroyed. This is when a player dies.


game:GetService('Players').PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character:WaitForChild("Humanoid").Died:Connect(function() local w = workspace.Clones:GetChildren() for i = 1, #w do if w[i].Name == player.Name .. " Clone" or w[i].Name == "Player.character.Name" or w[i].Name == "Player.Name" then w[i]:Destroy() end end end) end) end)

How do I make it so when the player leaves, the part gets destroyed ? I have tried this but it doesn’t work, how do I do it?


game:GetService('Players').PlayerAdded:Connect(function(player) player.CharacterRemoving:Connect(function(character) character:WaitForChild("Humanoid").Died:Connect(function() local w = workspace.Clones:GetChildren() for i = 1, #w do if w[i].Name == player.Name .. " Clone" or w[i].Name == "Player.character.Name" or w[i].Name == "Player.Name" then w[i]:Destroy() end end end) end) end)

4 answers

Log in to vote
0
Answered by 2 years ago
game.Players.PlayerRemoving:Connect(function(player)
    -- code to destory a part 
end)
Ad
Log in to vote
0
Answered by 2 years ago
game.Players.PlayerRemoving:Connect(function(player)
    -- code to destory a part 
end)
Log in to vote
0
Answered by 2 years ago

Use the PlayerRemoving function to achieve this.

local Part = game.Workspace.Part -- change this to where the part is

game.Players.PlayerRemoving:Connect(function()
    Part:Destroy()
end)
Log in to vote
0
Answered by 2 years ago

You can just do game.Players.PlayerRemoving

game.Players.PlayerRemoving:Connect(function(player)
    --logic here
end)

Answer this question