[EDIT] I managed to used 'for i' loop and CFrame to do what I needed to do.
Sorry if the title was misleading cause I have no idea what title to give it
I need help trying to do an if then break loop. Like if a part reaches a specific coordinate, it will break the loop which makes it stop moving.
Here is my script and at line 10, it underlines the '=' sign. It says 'Expected then, got ='
local base = game.Workspace.WaitForChild("Elevatorbase") local b2 = script.Parent function two() while true do wait(0.01) base.Position = base.Position+Vector3.new(0, 0.07, 0) end if base.Position = -2.525, 16.18, -12.125 then break end script.Parent.ClickDetector.MouseClick:Connect(two)
You need to detect position with item.Position == Vector3.new(x,y,z)
not item.Position = x,y,z
You simply used the wrong operator for this. And you forgot to put the break inside loop
Here is fixed script:
local base = workspace:WaitForChild("Elevatorbase") -- You dont need to use, and use :WaitForChild not .WaitForChild, game.Workspace..., you can use workspace... local b2 = script.Parent function two() while true do base.Position = base.Position + Vector3.new(0, 0.07, 0) if base.Position == Vector3.new(-2.525, 16.18, -12.125) then -- You needed to put this inside the place where the loop is, not out of loop --[[ do not use: if ... = ... then ... end use: if ... == ... then ... end --]] break end wait(0.01) end -- You forgot to put this end end script.Parent.ClickDetector.MouseClick:Connect(two)
Examples of conditional statsments:
-- 1 > Detect if is equal if 2 + 3 == 5 then print("two plus three is five") end --> Detect another equal example: (by: me) local number = 0 if number == 0 then print("Number is 0 ") else print("Number is not 0, the number is: " .. tostring(number)) end -- 2 > ~= operator if 100 ~= 4 then -- the '~=' operator means 'not equal to' print("100 is not equal to 4") end -- 3 > Else if 10 > 100 then print("10 is greater than 100") else print("10 is less than 100") end -- 4 > Elseif if 10 > 100 then print("10 is greater than 100") elseif 10 > 50 then print("10 is greater than 50") elseif 10 < 100 then print("10 is less than 100") end -- 5 > Detect bool values local pizzaPlaceIsOpen = false local tacoPlaceIsOpen = true local hotdogStandIsOpen = false --should output "Taco Place" with the above code if pizzaPlaceIsOpen == true then print("Pizza Place") elseif tacoPlaceIsOpen then -- var == true is usually unnecessary when var is a boolean print("Taco Place") elseif hotdogStandIsOpen then print("Hotdog Stand") else print("Hungry!") end
All examples is in roblox wiki.
Roblox wiki pages:
Hope it helped :D
this should work
local base = workspace:WaitForChild("Elevator") local b2 = script.Parent script.Parent.ClickDetector.MouseClick:Connect(function() repeat wait(0.01) base.Position = base.Position+Vector3.new(0,0.7,0) until base.Position = -2.525, 16.18, -12.125
1) You used the wrong operator (you initialize variables with an equal sign =). If you want to check if two things are equal to each other, you use the == operator. For example:
print('hello' == 'hello') -- true
2) You most likely accidentally pressed enter. You use conditional statements like this:
if x then ... code end -- or if x then code end
and not like this:
if x then ... code end
I suggest that you take a look at these pages: Operators, If statements