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

Why won't this script work?

I've asked this before, and got a good answer, but after awhile, when I clicked the part the Gui didn't go in the PlayerGui and the player couldn't see the Gui.

local gui =  script.Parent.Parent.Parent.night_GUI:Clone()

function Equip()
	gui.Parent = game.Players.LocalPlayer.PlayerGui
	wait(1)
	script.Disabled = true
	wait(60)
	script.Disabled = false
end
script.Parent.MouseClick:connect(Equip)

Any help please? THIS IS NOT A LOCALSCRIPT!

3 answers

✓ Accepted answer

Don't use Disabled to control your scripts.

For one thing, if the script is disabled it won't be able to undisable itself.

I'm not sure why you are disabling it.


A LocalScript probably won't run in a random brick in the workspace; regardless of where it is, I don't believe it can use a ClickDetector.

2 comments

0

No offense, but none of that makes sense to me. All I'm trying to do is that when a player clicks the part, a Gui goes into the playergui. No localscripts or random brick.

0

What he is saying is that when a script is disabled, it will quit whatever it is doing and stop functioning until it is enabled again. A disabled script is just that, disabled. It can not enable itself again.

I'd recommend using debounce instead of "disabled." Debounce makes a script inactive for a period of time, but it doesn't completely stop it. Here is your code I rewrote for you, using debounce:

local gui =  script.Parent.Parent.Parent.night_GUI:Clone()

function Equip()
    gui.Parent = game.Players.LocalPlayer.PlayerGui
    wait(1)
    debounce = true
    wait(60)
    debounce = false
end
script.Parent.MouseClick:connect(Equip)

Think of debounce, like a timer. The timer has to get to zero before it can be set again. Same applies in scripts. Debounce is like that timer. It prevents the script from reactivating for a period of time.

Only thing I see wrong is you need a wait(.5) at the top of the script cause local scripts load faster than roblox's respawning system.

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