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

Expected 'then' ,got '=' ?

Making a simple click detector move Vector3 script and the "=" on the 6th line is under lined red. when I hover my mouse over it " Expected 'then' ,got '=' " pops up. how do I solve this.

door=script.Parent
turn=1

function move()
	wait(0.1)
    if turn = 1 the do
    door.Position = door.Position + Vector3.new(0,-1,1)
	door.Rotation = door.Rotation + Vector3.new(90,0,0)
	turn = 0
    end
    end
	if turn = 0 then do
    door.Position = door.Position + Vector3.new(0,1,-1)
	door.Rotation = door.Rotation + Vector3.new(-90,0,0)
	turn = 1
	end
	end
end

door.ClickDetector.MouseClick:connect(move)

1 answer

✓ Accepted answer

The problem is that = is the assignment operator, but the equality operator is ==:

door=script.Parent
turn=1

function move()
    wait(0.1)
    if turn == 1 then
    door.Position = door.Position + Vector3.new(0,-1,1)
    door.Rotation = door.Rotation + Vector3.new(90,0,0)
    turn = 0
    end
    if turn == 0 then
    door.Position = door.Position + Vector3.new(0,1,-1)
    door.Rotation = door.Rotation + Vector3.new(-90,0,0)
    turn = 1
    end
end

door.ClickDetector.MouseClick:connect(move)

There are also a number of ways to improve this, such as using CFrames for moving the door rather than Position and Rotation. Additionally, you can (and should) use booleans rather than numbers, for example:

door=script.Parent
turn=true

function move()
    if turn then -- This is the same as 'if turn == true then' and is generally preferred.
        door.Position = door.Position + Vector3.new(0,-1,1)
        door.Rotation = door.Rotation + Vector3.new(90,0,0)
    else
        door.Position = door.Position + Vector3.new(0,1,-1)
        door.Rotation = door.Rotation + Vector3.new(-90,0,0)
    end
    turn = not turn -- This can be used to invert a boolean.
end

door.ClickDetector.MouseClick:connect(move)

1 comment

0

Thank you. Not scripted for a while and this skipped my mind.

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