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

GUI Enable script only works once after player died?

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)

2 answers

Try adding an if function that checks to see if the character is actually spawned. Have it wait until the player is fully spawned and loaded.

1 comment

0

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

Try checking the ResetOnSpawn property of the screen gui.

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