How would i make a button that disables a script when pressed?

Hi! I know it’s kinda weird, but i have a great idea in mind. I’m a terrible scripter, but i need some help with making a button that disables a script when a player clicks on it, but only for the players that clicked it. I have no idea if thats even possible, but any help would be appreciated :slight_smile:

1 Like

You should have certain points in your script where it can safely be stopped, to do this it should check a variable which is then controlled by your button. Don’t try to use the script’s enabled property, since this could stop basically anywhere that yields and sometimes just doesn’t work at all.


Would this system be server or client-sided?

i dont really know how i would do that though, because if one player presses it, than wont the entire server be affected?

to be honest i dont really know :sweat:

1 Like

Whatever is done on the server with either happen to all players or all players will be able to see it.
Whatever is done on the client can only happen or be seen by the player. Does that make sense?

yep! So it’s client based, so it would only affect the player(s) that clicked it

1 Like

Then the script has to be local.

it is

(ignore this for minimum)

An event for a clickdetector or gui click can control a variable that is shared with other code in the same script. That script then needs to have some places it can stop

--use a button to toggle this variable
local keepRunning = true

--Returns immediately if keepRunning is true
function CheckShouldPause()
    while not keepRunning do
        task.wait(1) --Wait until keepRunning is true again

while true do
--Do thing 1
--Do thing 2

Being able to choose where its okay to pause the script is an important feature here. The task.wait(1) is not ideal because the script will keep checking once a second. There is a better way to do this using bindable events, but this is the simplest way.

would i put this in the script that i want to de-activate? And if so where?

You can use this as a template to make a script that can be paused. You could also just use the CheckShouldPause function, your own variable, and your own button event.

i already have a script written though

The do the latter of the two.

what does that mean? Sorry if im getting really annoying idk how to code :sob:

1 Like

Don’t feel bad! You’re still learning! After all, you learn by asking questions!

1 Like