Script repeats on character death

All the scripts in startergui keeps repeating after resetting your character. How do I make a script only execute once? All the scripts are localscripts and they use events.
Here’s an example of a script that bugs out:

local RandomDoor = math.random(1,5)
local ReplicatedStorage = game:GetService("ReplicatedStorage")

if RandomDoor == 1 then 
ReplicatedStorage.Events.one:FireServer()
end

if RandomDoor == 2 then 
ReplicatedStorage.Events.two:FireServer()
	end

if RandomDoor == 3 then 
ReplicatedStorage.Events.three:FireServer()
		end

if RandomDoor == 4 then 
ReplicatedStorage.Events.four:FireServer()
			end

if RandomDoor == 5 then 
	ReplicatedStorage.Events.five:FireServer()
end

print("The first secret door is "..RandomDoor)
print("hello there")

local TPUI = game.StarterGui.TPTesting.Frame.SecretDoor
TPUI.Text = "The secret door is "..RandomDoor
2 Likes

If your gonna use it once, and only once, just do this:

After its ran, :Destroy()

1 Like

In a screen gui or just in the starter gui

All of the scripts are in StarterGui. They’re not in a ScreenGui.

Alright thanks, I’ll try it right now.

Ok, then i have no idea why, oof

Try having the parent as StarterPlayerScripts, that way, the script will only run once the player has joined.

Still repeats after resetting. I put script:Destroy() at the end and it still bugs out.

Thats a glitch. Delete the events so it cannot run.

So do I destroy the events after the script ends using Destroy()? Or just delete them

Try doing script.Disabled = true. This is because local scripts still run when parented to nil.

yes, that would be an easier way. Disable the script so it is not parented to nil, but actually just disabled. You can find disabling in the properties tab. Click on your script and there it will be.
To put this in a script write script.Disabled = true. Hope I could help :smiley:

This solution worked great! Thank you.

1 Like