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

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

Asked by 6 years ago
Edited 6 years ago

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)
1
When disabled is set to true, it stops the script from running. Did you maybe mix that up? User#20158 0 — 6y
0
You're right! It was. But now I have to ask again because something else happened! RobotChitti 167 — 6y
0
Well maybe try doing this: AswormeDorijan111 531 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

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)
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! RobotChitti 167 — 6y
0
Nice to hear that AswormeDorijan111 531 — 6y
Ad

Answer this question