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

"Playeradded" script working even on player death?

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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

Ad

Answer this question