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

Toggle script (true/false switch) is incorrect, help please ?

Asked by 7 years ago

I'm trying to do a test for later usage, it is about toggles. This is what I plan to do: When I click on a brick, it toggles between two different colors.

Here it is:

Trigger = script.Parent:WaitForChild('Switch').Trigger
Toggle = false

Trigger.MouseButton1Click:connect(function()
    if Toggle == false then
        Trigger.BrickColor = BrickColor.Red()
            Toggle = true
    else
        Trigger.BrickColor = BrickColor.Green()
            Toggle = false
    end
end)

It seems not to work... I have tried a lot of versions, which none of them worked, could anyone help me find the real, the functioning one, please ?

3 answers

Log in to vote
0
Answered by
OfcPedroo 396 Moderation Voter
7 years ago
Edited 7 years ago

Here, let's try the following:

Trigger = script.Parent:WaitForChild('Switch').Trigger
Toggle = false

Trigger.MouseButton1Click:connect(function()
    if Toggle == false then
    --Your problem is here. It's not BrickColor.Red(), it's BrickColor.new("Red"). But Red doesn't exist, so what you would want is BrickColor.new("Really red"): A red variant, pretty similar to the original one.
        Trigger.BrickColor = BrickColor.new("Really red")
            Toggle = true
    else
    --Your problem is ALSO here. It's not BrickColor.Green(), it's BrickColor.new("Green"). But, once more, Green doesn't exist, so what you would want is BrickColor.new("Dark green"): A green variant, pretty similar to the original one.
        Trigger.BrickColor = BrickColor.new("Dark green")
            Toggle = false
    end
end)

If this works, please mark as the solution!

As always, good scripting!

0
You're only fixing one issue with his script, which is BrickColor.new(), the other issue is because he isn't checking if Toggle is equal to true. StoleYourClothes 105 — 7y
0
I didn't even notice it before ! LordTechet 53 — 7y
0
@supersmartnoobguy Can you mark this as the answer? It took some time to write, besides, it's the correct one! OfcPedroo 396 — 7y
0
I could, but it didn't work LordTechet 53 — 7y
0
You should not really be asking for him to mark it as the answer. StoleYourClothes 105 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Hope this resolves your issue.

Trigger = script.Parent:WaitForChild('Switch').Trigger
Toggle = false

Trigger.MouseButton1Click:connect(function(OnClicked)
    if Toggle == false then
        Trigger.BrickColor = BrickColor.new("Really red")
            Toggle = true

    elseif Toggle == true then
        Trigger.BrickColor = BrickColor.new("Bright green")
            Toggle = false
    end
end)
Log in to vote
0
Answered by 7 years ago

I managed to find and fix it now, I appreciate that you guys wanted to help me, but none of the answers you gave me were correct...

Boy = script.Parent
Toggle = true

function OnClicked()
    if Toggle == true then
        Boy.BrickColor = BrickColor.new("Bright green")
        Toggle = false
    else
        if Toggle == false then
            Boy.BrickColor = BrickColor.new("Bright red")
            Toggle = true
        end
    end
end

Boy.ClickDetector.MouseClick:connect(OnClicked)
0
Did you try my version? It is alot cleaner. And now you have switched it to a ClickDectector? You could've of elaborated your question more to tell us that it was for a ClickDetector and not a GraphicalUserInterface. Completely your fault, and what a waste of time. Real, nice. StoleYourClothes 105 — 7y
0
Sorry, my bad ! LordTechet 53 — 7y

Answer this question