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

Why won't this script work?

Asked by 9 years ago

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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

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. PyccknnXakep 1225 — 9y
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. User#348 0 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

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.

Log in to vote
0
Answered by 9 years ago

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.

Answer this question