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

Can anyone help with my if statement?

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

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)

3 comments

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.

2

Line 10: "Anchored = true"

0

My bad, I didn't catch that. Sorry.

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