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!
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
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)