I have a main menu GUI, and I implemented a script that re-enables it once the player dies. It only seems to work once, though. If the player dies more than one time it doesn't do anything. This is what it looks like:
game.Players.PlayerAdded:Connect(function(p)
p.CharacterAdded:Connect(function(c)
c.Humanoid.Died:Connect(function()
wait(5)
p.PlayerGui.MainMenu.Enabled = true
workspace.Menu:Play() -- "Menu" being a sound object
end)
end)
end)
In case it helps, this is the script of the button that closes the menu:
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Parent.Enabled = false
workspace.Menu:Stop() -- "Menu" being a sound object again
end)
edit: all scripts in StarterGui are local, and the first script listed is a normal script in ServerScriptService
edit 2: Using a print function I've found out that in the first script, it actually does run every time I die, but after the first time of dying it seems to ignore any code I have in the Humanoid.Died function
edit 3: I found a new way of making the script that seems to help a little bit. Instead, I put this into "StarterPlayerScripts" and edited it so it looks like this:
p = script.Parent.Parent
wait(5) -- wait for character to load
p.Character.Humanoid.Died:Connect(function()
wait(5)
p.PlayerGui.MainMenu.Enabled = true
workspace.Menu:Play()
print(1)
end)
Now, it actually resets the menu music (which it wasn't doing before), and also stops printing "1" after my character died for the first time (which is more consistent than before)

1 comment
That seemed to make it not work at all instead of only working once. Thanks for the suggestion, though