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

How to make a local script destroy itself?

Asked by 4 years ago

I was working a game which has more to come but I made it multi platformed gui so if you clicked on one of the options (pc, mobile) it would fit the gui to that screen (ui scaling) whenever you die or reset the gui pops up again. I tried to make it not pop up again with a local script with the following I set the gui enablility to false for the script

script.parent.Enabled = true

if script.parent.Enabled == false then
     script:Destroy()
end

It might not make sense to you because I put a local script when you clicked a button, what it would do is set the gui enability to false. by destroying the script the gui would not appear since its true enability is false and the local script is the only thing making it true

3 answers

Log in to vote
0
Answered by 4 years ago

The script is not destroying itself because the script is only checking to see if the parent is enabled once. This being said, you have to develop something that continuously checks, or checks every time. If the condition is inside of a function or an event, then you should be fine. However, from what I can see it seems like you are only checking once.

In order to check continuously, you should use the following loop:

coroutine.resume(coroutine.create(function()
    script.Parent.Enabled = true
    while wait() do
        if not script.Parent.Enabled then
            script:remove()
        end
    end
end))

If this is not what you were looking for please let me know, but I hope this helps!

Ad
Log in to vote
0
Answered by
bountor -5
4 years ago

script.parent.Enabled = true

if script.parent.Enabled == false then script.Parent:Destroy() end

0
you did not put parent bountor -5 — 4y
0
what if I want to destroy the script HollyIsTheBestOne -48 — 4y
0
yea u do script.Parent:Destroy() bountor -5 — 4y
Log in to vote
0
Answered by 4 years ago

Well depends how you want it to destroy. If you want to remove it permanently from the game you cant, because it will destroy in the client but it will stay into the other players. If you wanna remove it from the whole server you will need to use a server script for that probably.

Answer this question