Players on Low-end devices are not being teleported to the map

Hi Devs!

So i’ve encountered a problem with the player occasionaly NOT being teleportated to the map. Here’s the part of the server-sided script which is responsible for teleportating the player:

rs.WeaponSystemEvents.PlayPressed.OnServerEvent:Connect(function(plr)
	if RoundBegan then
		if #currentSpawns > 0 then
			local randomSpawn = currentSpawns[math.random(1, #currentSpawns)]
			
			if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") then
				plr.Character.HumanoidRootPart.CFrame = randomSpawn.CFrame + Vector3.new(0, 5, 0)
			end
		end
	else
		mapevents.Deny:FireClient(plr) --if the round didn't start, fire this event (prints out a word, nothing more)
	end
end)

It happened to other people who have potato wifi or just bad ping, maybe that’s the problem? Like the script isn’t optimized..?

I’d be glad for any help provided! Also if you need some more details, please let me know! :hidere:

5 Likes

well, that’s gonna be a kinda bad problem…

2 Likes

Encountered this issue several times in the past. Likely happens due to the network ownership of the character is on the player, and you are teleporting them on the server side.

Setting their CFrame on the client side should help :+1:

4 Likes

I always have an uneasy feeling when teleporting players, so what I do instead is repeatedly teleport them and run magnitude checks until they’re close enough to the target.

local config = {
	maxAttempts = 10,
	teleportInterval = 0.5,
	teleportRadius = 4, -- how far the player must be from the target for the teleport to be considered successful
	yOffset = 2
}

local function teleport(player: Player, cframe: CFrame) : boolean
	local attempts: number = 0
	local teleportFinished: string
	
	repeat
		local try, err = pcall(function()
			player.Character:PivotTo(cframe + Vector3.new(0, config.yOffset, 0)) -- comment out this line to simulate max attempts
			
			local rootPos: Vector3 = player.Character.PrimaryPart.Position
			local targetPos: Vector3 = cframe.Position
			
			local magnitude: number = (rootPos - targetPos).Magnitude
			if magnitude < config.teleportRadius then
				teleportFinished = true
			else
				attempts += 1
				warn(`[teleport] teleport failed for player \"{player.Name}\". retrying ({attempts}/{config.maxAttempts})\n`)
			end
		end) 
		
		if not try then
			warn(`[teleport] teleport failed for player \"{player.Name}\". retrying ({attempts}/{config.maxAttempts})\nErr: {tostring(err)}`)
			attempts += 1
		end
		
		task.wait(config.teleportInterval)
	until attempts >= config.maxAttempts or teleportFinished == true
	
	if attempts >= config.maxAttempts then
		warn(`[teleport] teleport failed for player \"{player.Name}\" (max attempts reached)`)
		return
	elseif teleportFinished == true then
		print("teleport success")
		return true
	end
end

teleport(game.Players:WaitForChild("halosviel"), workspace.Part.CFrame)

Just wrote this script now, works well :+1:

5 Likes

Thank you @VioletElementalist and @halosviel ! I’ll try these methods as soon as possible and mark the solution if it worked

2 Likes

Could it perhaps be because of workspace.StreamingEnabled being on?
If you have it on, try turning it off.

It is already turned off, sadly

Thank you a lot for an easy solution! Now players with 600+ ping can enjoy the game… idk how they’re not ragequitting

I haven’t tested with multiple teleportations cuz I don’t want the game to be unoptimized, maybe it works too

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.