My script is supposed to give a player a table which indicates the route they can go. The table is passed via a remote event. It works perfectly fine the first time the remote event is fired, but the second time the player just doesn’t go to their proper location, nor is the movement GUI which allows them to teleport visible. I tried using more remote events to make it work but it ended up with the same outcome. What is the problem?
player = game.Players.LocalPlayer
character = player.Character or player.CharacterAdded:Wait()
humanoid = character:WaitForChild("Humanoid")
assignRoutes = game.ReplicatedStorage.Remotes.AssignRoutes
doorTeleports = workspace.EmptyHouse.BloxianTeleports.DoorTeleports
canPass1 = game.ReplicatedStorage.Remotes.CanPass1
canPass2 = game.ReplicatedStorage.Remotes.CanPass2
getWeapon = game.ReplicatedStorage.Remotes.GetWeapon
door1 = workspace.EmptyHouse.Door1.Closed
door2 = workspace.EmptyHouse.Door2.Closed
moveOn = script.Parent.MoveOn
assignRoutes.OnClientEvent:Connect(function(path)
local index = 1
local timer = 0
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
character:MoveTo(path[index].Position)
print("Route Received")
wait(15)
moveOn.Visible = true
moveOn.MouseButton1Click:Connect(function()
timer = 0
if index == #path then
if path[index] == doorTeleports.Door1 then
if not canPass1:InvokeServer() then
character:MoveTo(workspace.EmptyHouse.BloxianTeleports.JumpscareZone.Position)
else
index = 0
end
end
if path[index] == doorTeleports.Door2 then
if not canPass2:InvokeServer() then
character:MoveTo(workspace.EmptyHouse.BloxianTeleports.JumpscareZone.Position)
else
index = 0
end
end
end
index = index + 1
character:MoveTo(path[index].Position)
moveOn.Visible = false
wait(8)
moveOn.Visible = true
while moveOn.Visible do
wait(1)
timer = timer + 1
if timer == 8 then
index = 1
character:MoveTo(path[index].Position)
break
end
end
end)
end)