Internet lag is breaking one of my code

I have a script where it teleports you to a map and gives the player a sword. But I have noticed if you are lagging then the game won’t teleport you but you will still get a sword. Is there any way to stop this from happening? Thank you for reading

Here’s my code for teleporting so far:

for i, player in pairs(plrs) do 
		player.Team = game.Teams.Playing
		SS:FireAllClients(false)
		ES:FireAllClients(false)
		MS:FireAllClients()
		LivesReplicated:FireAllClients(true)

		if player then
			character = player.Character

			for _, tool in pairs (player.Backpack:GetChildren()) do
				if tool:FindFirstChild("Price") then
					tool:Destroy()
				end
			end

			for _, tool in pairs (character:GetChildren()) do
				if tool:FindFirstChild("Price") then
					tool:Destroy()
				end
			end

			if character then
				-- Teleport them
				
				character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
				table.remove(AvailableSpawnPoints, 1)

				character:FindFirstChild("Humanoid").Health = 150

				local equipped = game.ServerStorage.PlayerData[player.Name].Equipped

				if equipped.Value ~= "" then
					local weapon = game.ServerStorage.Items[equipped.Value]:Clone()
					weapon.Parent = player.Backpack
				else
					local sword = game.ServerStorage.ClassicSword:Clone()
					sword.Parent = player.Backpack
				end

				local GameTag = Instance.new("BoolValue")
				GameTag.Name = "GameTag"
				GameTag.Parent = player.Character
			else
				-- There is no character (prolly left)
				if not player then
					table.remove(plrs, i)
				end
			end
		end
	end

*the teleporting code starts in the if character part

1 Like

Have you tried using a remote event to teleport the players?

1 Like

After You Teleport The Player In The Server, Fire A Remote Event That Awares The Player To Teleport Themselves On Client.