Why is my script not working the second time the remote event is fired?

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)
2 Likes

Do have gifs or video of this not working the second time?

I can make one if you want, but basically what I mean by it not working is the character isn’t teleporting to the first location in the route table. Also the gui that allows to to go to the next spot in the route is not turning visible either.

And this is for the second time firing correct?

Yes, also all the times after the second time. Basically after the first time the remote event fires, when it fires again it doesn’t do what it did the first time.

Does it print route received on the second time?

Yes, it prints route received the second time, but I don’t teleport where I am supposed to go. Also I am able to move freely and jump freely, something the script was supposed to turn off.