Hey!
I’ve made a system for teleporting players to a race location, however it seems to be occasionally failing for users with high ping. It seems to be doing everything correctly except for forcing the player to sit in their newly spawned car.
Video of the issue occurring for one of my high ping testers:
Server sided code (The teleport system is fully server sided):
function Race:_teleportPlayers(queue, player)
coroutine.resume(coroutine.create(function()
local spawns = self.Instance.Spawns
local function GetLocation()
for i, v in pairs(queue) do
if v.Name == player.Name then
Knit.Services.QueueService.Client.PlayerLeft:Fire(player, self.Instance.Name)
Knit.Services.RaceService.Client.RaceStarting:Fire(player, self.Instance.Name)
return i
end
end
end
local location = spawns[GetLocation()]
local InventoryName = player.Name .. "sInventory"
player:RequestStreamAroundAsync(location.Position)
local carName = player.Name .. "sCar"
local car = workspace:WaitForChild(carName)
local clonedCar = ServerStorage[InventoryName]:FindFirstChild(carName):Clone()
clonedCar.Name = player.Name .. 'sCar'
clonedCar:SetPrimaryPartCFrame(location.CFrame)
workspace.ChildAdded:Connect(function(child)
local function SitAndStart()
print(workspace:WaitForChild(carName).DriveSeat)
if child.Name == carName then
task.delay(2, function()
-- ISSUE OCCURS WITH THE LINE BELOW
workspace:WaitForChild(clonedCar.Name).DriveSeat:Sit(player.Character.Humanoid)
end, workspace:WaitForChild(carName).DriveSeat)
end
end
task.defer(SitAndStart)
end)
workspace.ChildRemoved:Connect(function(child)
if child.Name == carName then
task.wait(0.1)
clonedCar.Parent = game.Workspace
end
end)
car:Destroy()
end))
end
I’ve tried implementing some event based logic, as well as some features from the new task library, however they seem to have provided minimal, if not any improvement. Again, everything seems to be working as intended except for forcing the player to sit. Additionally, no errors related to this script are being thrown.