When a vehicle gets spawned, it’s positioned, parented to a folder in workspace and then calls seat:Sit() for the player. I’m having a problem currently though, with that when I use this function sometimes the controls break. I’ve narrowed down the problem to it’s something to do with sitting the player, because if I disable seat:Sit() (comment it out) and then walk over to the seat instead, the controls always work. But currently only sometimes the controls work, does anyone have an idea to why this is happening?
I really didn’t want to make a devforum post but I’ve spent two entire days trying to figure out a solution to this problem so I’m clearly missing something. I’ve looked at at least 20 posts but none of them have helped me. I’m using the default jeep from the race template and you can view the relevant parts of my code below, the player is seated at the very bottom of the script.
This has been solved so I’ve removed the code to prevent copying.
The main problem with your code is that it does not wait for the player’s character to spawn before trying to sit them in the car. This can cause problems because the car may not exist yet, or the player’s character may not be loaded.
To fix this, you can add a wait() call before the task.delay() call, which will wait for the player’s character to spawn before trying to sit them in the car.
Your code wasn’t wrong, per se, but there was a problem with the way the player was being seated in the vehicle. In the original code, the player was being seated as soon as the vehicle was spawned. This caused some problems with the player’s controls, because the player wasn’t given enough time to adjust to the new vehicle. By delaying the seating of the player by 0.5 seconds, this problem is alleviated.
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
if player.Character:WaitForChild("Humanoid").Sit then
player.Character.Humanoid.Sit = false
local spawnPos = currentCourse.SpawnPositions
local carSettings = customCarStore:GetAsync(player.UserId.."-settings")
if carSettings.Car then
carClone = Vehicles[carSettings.Car]:Clone()
carClone = Vehicles.Jeep:Clone()
carClone.Name = "Vehicle"
local seat = carClone:FindFirstChildWhichIsA("VehicleSeat")
if not carClone.PrimaryPart then
carClone.PrimaryPart = seat
carClone:PivotTo(spawnPos:GetPivot() * CFrame.new(0,4,0))
carClone.Parent = game.Workspace.Vehicles
This might be the same code, I said I rescripted the code.
I’ve seen this issue before but am not famililar with how to fix… my only suggestion would be to try to separate the functions. So first clone the vehicle into the workspace, then in a separate function, sit the humanoid.
I’ve been able to fix it… somehow. I fixed it a couple of days ago but wanted to do thorough testing before coming to a conclusion and now I can’t remember how I fixed it. I think it was that other bits of my script were programmed really poorly because I just returned to this project after not working on it for a few months.
If anyone else encounters this problem, my only suggestion would be to see if other bits of your script are breaking it.