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

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

Are you sure that there is no other script that overwrites the player position during/after a jump? Since the script prints out all the debug messages, I imagine there is something else going on here.

local Position = workspace.Depart.Spawn:GetChildren()
local RandomPosition

--Function blablabla
if v.Character then
  RandomPosition = Position[math.random(1, #Position)]
  v.Character.HumanoidRootPart.CFrame = RandomPosition.CFrame
end

No bugs appeared after about 50 tries, it seems more stable (fingers crossed)

No other script that interfer no, the problem seem to be fixed, this is probably related to an instability of the random inside a CFrame

2 Likes