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 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
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 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…
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
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.