Hay! im trying to create a teleport loop.
So whats the problem? Well, it doesent print() after i say “go” after “stop”. But it does stop.
local playG = "go"
local playS = "stop"
game.Players.LocalPlayer.Chatted:Connect(function(msg)
if msg:sub(1, playG:len()):lower() == playG then
print("Teleporting: ✅")
teleport = true
end
end)
game.Players.LocalPlayer.Chatted:Connect(function(msg)
if msg:sub(1, playS:len()):lower() == playS then
print("Teleporting: ❌")
teleport = false
end
end)
while teleport == true do
print("Teleporting...")
wait(2)
end
The issue is that the while loop will only loop once. Once teleport is set to false the while loop will never run again even if you set teleport back to true.
local playG = "go"
local playS = "stop"
local teleport = true -- Disregard this if you have this variable declared somewhere else
game.Players.LocalPlayer.Chatted:Connect(function(msg)
if teleport == true then return end
if msg:sub(1, playG:len()):lower() == playG then
print("Teleporting: ✅")
teleport = true
while teleport == true do
print("Teleporting...")
wait(2)
end
end
end)
game.Players.LocalPlayer.Chatted:Connect(function(msg)
if msg:sub(1, playS:len()):lower() == playS then
print("Teleporting: ❌")
teleport = false
end
end)