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

How do I most effectively stop a GUI button from 'breaking' when a player dies?

Asked by 8 years ago

I've put the GUIs in the StarterGui since having them spawned via script into the PlayerGui caused them to be deleted when the player respawned.

However, the GUIs don't function as intended after the player dies. I've asked the function in question to fire when the player clicks on the GUI. It works as intended until the player dies and respawns. That is when the GUI will stop connecting the function when it is clicked.

Here's a script that emulates this behaviour:

function ExampleFunction()
    N = Instance.new("Message", game.Workspace)
    N.Text = "Message"
    wait(3) 
    N:remove()
end

game.Players.LocalPlayer.PlayerGui.Example.ExampleButton.MouseButton1Down:connect(ExampleFunction)

The function "ExampleFunction()" will stop being fired after the player resets/respawns, though the button remains. There are no error messages. Please help me.

1
StarterGui still spawns a copy inside the PlayerGui every time the character respawns, so every reference you keep is to the original gui. If the LocalScripts are inside a ScreenGui then it will run again every time the gui loads. 1waffle1 2908 — 8y
0
1waffle1, are you telling me to place the local script in the StarterGui itself? I will try that ^_^ alikabeth 25 — 8y
0
I though Message was deprecated but.... yougottols1 420 — 8y
0
@yougottols1 It's an example, haha. alikabeth 25 — 8y

Answer this question