Sometimes, the player does not teleport at the end of the round help

Hi, sometimes the player doesn’t teleport at the end of the round and I don’t know why. I noticed that it seems to happen especially when the player jumps pill at the end of the round, but I am not sure. I specify that the character is supposed to be loaded it’s just the teleportation that doesn’t happen (it happens rarely but it happens). Here is the function that teleports players when a round starts. Thanks for reading !

for i, v in ipairs(Players:GetPlayers()) do
			startgame = true
			if Players:FindFirstChild(v.Name) then
				if v.PlayerGui:FindFirstChild('Toujours') and v.PlayerGui.Toujours:FindFirstChild('Scripts') then
					for i,v in ipairs(v.PlayerGui.Toujours.Scripts:GetChildren()) do
						v:Destroy()
					end
					if v.Character then
						randomPo = math.random(1,4)
						if randomPo == 1 then
							v.Character.PrimaryPart.CFrame = CFrame.new(math.random(-100.343,-64.865), 7.79, math.random(108.083, 124.635))
						elseif randomPo == 2 then
							v.Character.PrimaryPart.CFrame = CFrame.new(math.random(-77.016,-61.082), 7.79, math.random(68.964, 105.058))
						elseif randomPo == 3 then
							v.Character.PrimaryPart.CFrame = CFrame.new(math.random(-119.187,-105.115), 7.79, math.random(64.613, 81.164))
						elseif randomPo == 4 then
							v.Character.PrimaryPart.CFrame = CFrame.new(math.random(-122.243,-106.574), 7.79, math.random(87.42, 122.836))
						end
					end

                 -- BLABLABLA

I saw someone with the same issue in this previous post but this wasn’t resolved Player sometimes doesn't teleport to the round

I would simply just use a for i, v in pairs() loop. Then, insert the players in a table, then loop through that table and teleport them all at once. I don’t know why you’re using math.random() for this task, but if you’re trying to do what I said above, then I’d reccomend just removing that.

I just was having the same problem in my game.
What I did to fix it was fire a RemoteEvent to the client with the position to teleport to, and have the player teleport themselves instead of doing it server-side.

I use random math to determine the position of the player when he teleports, in order to scatter the players, there is a big hole in the middle so I have to make them appear on the sides hence the random math. This should have no impact on the teleportation of the players. Besides, putting all the players in a table doesn’t seem any easier than the way I use. All my system works except this little part because teleportation is not done from time to time, I have seen this problem on many games

I would like to avoid using a FireAllPlayers to teleport them, all my system works without any event, I don’t understand why teleporting players doesn’t work from time to time it’s weird. Thanks for your feedback

You should add some logs at each part of your method to figure out where exactly it’s failing. for instance. It’ll make it much easier for you to debug on your own:

for i, v in ipairs(Players:GetPlayers()) do
			startgame = true
            print("Success 1")
			if Players:FindFirstChild(v.Name) then
                print("Success 2")
				if v.PlayerGui:FindFirstChild('Toujours') and 
                    print("Success 3")v.PlayerGui.Toujours:FindFirstChild('Scripts') then
					for i,v in ipairs(v.PlayerGui.Toujours.Scripts:GetChildren()) do
						v:Destroy()
					end
					if v.Character then
                    print("Success 4")
						randomPo = math.random(1,4)
						if randomPo == 1 then
							v.Character.PrimaryPart.CFrame = CFrame.new(math.random(-100.343,-64.865), 7.79, math.random(108.083, 124.635))
						elseif randomPo == 2 then
							v.Character.PrimaryPart.CFrame = CFrame.new(math.random(-77.016,-61.082), 7.79, math.random(68.964, 105.058))
						elseif randomPo == 3 then
							v.Character.PrimaryPart.CFrame = CFrame.new(math.random(-119.187,-105.115), 7.79, math.random(64.613, 81.164))
						elseif randomPo == 4 then
							v.Character.PrimaryPart.CFrame = CFrame.new(math.random(-122.243,-106.574), 7.79, math.random(87.42, 122.836))
						end
					end

                 -- BLABLABLA
1 Like

What I would do is, do what I said before. Then, use the wait() function, and wait a couple of seconds. Then, loop through the player table, and then assign the random positions for them. You could’ve been getting an issue because the math.random script affects the player before the script is done teleporting the player.

I haven’t even checked where there is a problem yet, I’ll see now thanks

1 Like

I managed to make the problem appear, this problem never happened on Roblox Studio it appears when I play on Roblox. All the prints have been detected and so no problem with the script, just the player that doesn’t teleport…


Succes5 appear but no teleport.

It really seems to appear when I jump when the round is over, it never appeared otherwise

If success 5 appears, then print the random value and then add print statements in each if statement. There’s no reason why your if statements shouldn’t work, but let’s just see. Just in case.

I specify that before the bug appeared the script worked normally about ten times and suddenly the problem appeared, I was alone in the server and I did not die once in the server

Ok let me try thanks for your help

Well, after about 30 tries the problem appeared only once and when it appeared it detected the print(‘Succes3’)

I’m pretty sure it’s like a bug

If you’re still having issues, I did see this about math.random(). Evidently, it’s bad practice to use decimals in math.random.

You could also use something like the following:

local random = Random.new()
print(random:NextInteger(1, 10)) -- 4
print(random:NextNumber(1, 10)) -- 6.2352857523455
1 Like

Ohhh so you think it’s a problem related to the math random, thank you i’m going to try it

If everything is working up to the math.random part, then that’s my only other guess. You are updating these CFrames on the server, right?

Yes, it’s all in the server, i’m going to try thank you

1 Like

The problem is the same. I think I’ll put several parts in one folder and teleport the player randomly to one of the parts to see if it work better

	    random = Random.new()
		randomPo = math.random(1,4)
		if randomPo == 1 then
			v.Character.PrimaryPart.CFrame = CFrame.new(random:NextInteger(-100,-64), 7.79, random:NextInteger(108, 124))
		elseif randomPo == 2 then
			v.Character.PrimaryPart.CFrame = CFrame.new(random:NextInteger(-77,-61), 7.79, random:NextInteger(68, 105))
		elseif randomPo == 3 then
			v.Character.PrimaryPart.CFrame = CFrame.new(random:NextInteger(-119,-105), 7.79, random:NextInteger(64, 81))
		elseif randomPo == 4 then
			v.Character.PrimaryPart.CFrame = CFrame.new(random:NextInteger(-122,-106), 7.79, random:NextInteger(87, 122))
		end

Good luck! Let me know how it goes! Sorry we couldn’t figure out the problem. My guess is that it is just a bug, like you said. It’s so inconsistent that I really can’t think of another issue with it.

1 Like

Thank you for your help and your time i’ll update when i find a solution