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

How do I make the union unanchor when I unscrew all the nails?

Asked by 7 years ago

So I was able to make four nails that can each be unscrewed with a click and I want them to unanchor a union when I unscrew all the nails, so I used this code in the union below:

while true do
    if game.Workspace.Nail1.Anchored = false
        then if game.Workspace.Nail2.Anchored = false
            then if game.Workspace.Nail3.Anchored = false
                then if game.Workspace.Nail4.Anchored = false
                    then script.Parent.Anchored = false
                end
            end
        end
    end
end

The problem is that the script doesn't work because it has the red underline under the first equal sign, and I don't know how to fix it. WHY?!?!

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

There are a few things that can be fixed here.

First of all, when doing if then statements, it requires a double equal (==) sign. Secondly, you can condense this into one if then statement. Lastly, make sure to add a delay in the while true do, so you don't kill your studio when running.

while true do
    wait()
    if not game.Workspace.Nail1.Anchored and not game.Workspace.Nail2.Anchored and not game.Workspace.Nail3.Anchored and not game.Workspace.Nail4.Anchored then
                    then script.Parent.Anchored = false
end
end


Hope I helped!

Ad
Log in to vote
-3
Answered by 7 years ago
while true do
function onClicked(ObjectName)
    game.Workspace.ObjectName.Anchored = false then
    game.Workspace.Nail1.Anchored = false
        game.Workspace.Nail2.Anchored = false
            game.Workspace.Nail3.Anchored = false
                game.Workspace.Nail4.Anchored = false
                    script.Parent.Anchored = false
                end
            end
        end
    end
end
game.Workspace.ObjectName.ClickDetector:connect(onClicked)

try that sorry I had no time to go on studio mode!

warning: name ObjectName the objects name

Hope this helped enjoy!

Answer this question