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)
