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

*RESOLVED* How do I Enable/Disable a Script After Clicking the Part? Did I mess up the Script?

I don't know how, but I forgot how this works. I have two scripts. One is for one part as the turn on/off button and the other for the other buttons' functions. Well, for this script, I want to click the button, or Switch, and turn on/off, or Enable/Disable, the script which is called Main. I don't know if that is possible. And if it is, then what did I do wrong here. The on/off button works, but it didn't enable or disable the script. Thank you for helping me!

Switch = script.Parent.Parent.Switch
switchOn = false
local onoff = game.Workspace.RemoteControl.Pad.Main
onoff.Disabled = false 

function onClicked()
    if not switchOn then
        switchOn = true
    Switch.CFrame = Switch.CFrame+Vector3.new(0,-0.09,0)
	Switch.BrickColor = BrickColor.new("Shamrock") 
	onoff.Disabled = true -- Enabling the script
    elseif switchOn then
		switchOn = false
    Switch.CFrame = Switch.CFrame+Vector3.new(0,0.09,0)
	Switch.BrickColor = BrickColor.new("Bright red")
	onoff.Disabled = false -- Disabling the script
        end
    end

script.Parent.Parent.Switch.ClickDetector.MouseClick:connect(onClicked)

3 comments

1

When disabled is set to true, it stops the script from running. Did you maybe mix that up?

0

You're right! It was. But now I have to ask again because something else happened!

0

Well maybe try doing this:

1 answer

✓ Accepted answer

Try this script:

Switch = script.Parent.Parent.Switch
switchOn = false
local onoff = game.Workspace.RemoteControl.Pad.Main
onoff.Disabled = false 

script.Parent.Parent.Switch.ClickDetector.MouseClick:Connect(function()
    if switchOn == true then

     switchOn = false
    Switch.CFrame = Switch.CFrame+Vector3.new(0,0.09,0)
    Switch.BrickColor = BrickColor.new("Bright red")
    onoff.Disabled = false -- Disabling the script.

    else
    switchOn = true
    Switch.CFrame = Switch.CFrame+Vector3.new(0,-0.09,0)
    Switch.BrickColor = BrickColor.new("Shamrock") 
    onoff.Disabled = true -- Enabling the script
       
end
end
end)

2 comments

0

I had to remove the 'end' on Line 22 since there was an error. It also works too. I already figured it out but they both work the same!

0

Nice to hear that

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