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

Can anyone help with my if statement?

Asked by 9 years ago

So the code runs perfectly until it goes into the if statement part (line 8 - end). The correct code and/or an explanation on what I did wrong would be highly appreciated.

Anchored = script.Parent.Anchored

script.Parent.Touched:connect(function()
    script.Parent.BrickColor = BrickColor.new("Bright red")
    script.Parent.Anchored = false
end)

if Anchored == false then
    wait(3)
    Anchored = true
    script.Parent.BrickColor = BrickColor.new("Brown")
    script.Parent.Position = Vector3.new(-45, 18, -17.5)
end

1 answer

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
9 years ago
Anchored = script.Parent --Variable has to be the instance, not the property's value.

script.Parent.Touched:connect(function()
    script.Parent.BrickColor = BrickColor.new("Bright red")
    Anchored.Anchored = false
if Anchored.Anchored == false then --If statement inside of the function.
    wait(3)
    Anchored = true
    script.Parent.BrickColor = BrickColor.new("Brown")
    script.Parent.Position = Vector3.new(-45, 18, -17.5)
end
end)
0
Actually it doesn't matter that he set the variable directly to the property, since he wasn't trying to change it.. he was just comparing it. Goulstem 8144 — 9y
2
Line 10: "Anchored = true" Discern 1007 — 9y
0
My bad, I didn't catch that. Sorry. Goulstem 8144 — 9y
Ad

Answer this question