✓ Accepted answer
this may fix it
local boat = script.Parent
local CanTeleport = false
local teleportscript = game.Workspace.Teleports.TeleportPad1.Teleport
local function BoatMove()
while true do
wait(10)
for i = 1,300 do
boat:TranslateBy(Vector3.new(1,0,0))
wait()
end
for i = 1,300 do
boat:TranslateBy(Vector3.new(-1,0,0))
wait()
end
end
end
local function CanTeleportToggle()
while true do
CanTeleport = true
wait (10)
CanTeleport = false
wait (10)
end
end
local function CanTeleportCheck()
while true do
if CanTeleport == false then
teleportscript.Disabled = true
elseif CanTeleport == true then
teleportscript.Disabled = false
end
wait()
end
end
spawn(BoatMove)
spawn(CanTeleportToggle)
spawn(CanTeleportCheck)
Basically what went wrong was the code was not able to advance due to the while loops not being in a coroutine or spawn. I went with spawn() for this, but you could also use coroutine.wrap(), both yielding pretty much the same result. Also, your if statement at the end of your code needed to be changed to be in a while loop. This way should work, but infinitely looping isnt always the best way to do things. If I were you, I would look into other options such as GetProperyChangedSignal(). If anything here doesnt work, or you need help, feel free to ask
3 comments
If you want to run two while loops concurrently, you should look at coroutines as only one (the first one) will run. Secondly even if both loops were running, the if condition is only checked once so changes to CanTeleport won't be sensed.
Yeah, you should coroutine.wrap() your loops if you want to check for that if statement while it's running. (And preferably put it in the loop if you want to consciously check it).
Also you should know that wait()'s duration can vary wildly. If this is supposed to take a spesific amount of time you should provide a time period.