Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

"Playeradded" script working even on player death?

Okay so, I basically put a script with a player added function. I want to make a GUI appear just once as Playeradded function is intended. But the GUI keeps appearing after dying. What's wrong?

function onPlayerAdded(Player)
...
end

game.Players.PlayerAdded:Connect(onPlayerAdded)

for _, player in pairs(game.Players:GetPlayers()) do
	onPlayerAdded(player)
end

1 answer

You'll want to connect a function to Humanoid.Died to delete the GUI. Something like so:

game.Players.PlayerAdded:Connect(function(player) --When a player joins
    --You will want to add your GUI here under PlayerAdded
    player.CharacterAdded:Connect(function(character) --When they spawn
        character.Humanoid.Died:Connect(function() --When they die
            WhateverGui:Destroy() --Replace WhateverGui with the desired GUI to delete
        end)
    end)
end)

Also, if you just want the GUI to be added on a player's joining, lines 7-9 are unnecessary and are probably harmful in fact.

You'll want to add some more code under the Died event to make sure it only happens once. I'll leave that to you :)

Happy scripting

This discussion is preserved as it was. New answers, comments, and votes are closed.