I am trying to make a script so that when a car is spawned, the player’s character sits in the vehicleseat. The car spawn script is server-sided, and I’m wondering if there is a way to make the character sit from the server-sided script. This is the script:
local posa = game.Workspace.CarPosA
game.ReplicatedStorage:WaitForChild("CheckPrice").OnServerInvoke = function(player,NameOfCar)
return game.ServerStorage.Cars:FindFirstChild(NameOfCar).Price.Value
end
game.ReplicatedStorage:WaitForChild("SpawnCar").OnServerEvent:Connect(function(player,NameOfCar)
local car = game.ServerStorage.Cars:FindFirstChild(NameOfCar):Clone()
car:SetPrimaryPartCFrame(posa.CFrame)
car.Parent = workspace.Vehicles
car:MakeJoints()
car.Name = player.Name.."'s "..NameOfCar
end)
I know I could do something like this in StarterCharacterScripts but it doesn’t work server-sided:
This won’t work because I have my seats Disabled check set to true so that players cannot walk into the seat.(This still allows players to sit to drive through a script)
In that case, you’re gonna have to use a RemoteFunction instead of a RemoteEvent. When it’s invoked, run the code on the server but don’t make the player sit. Instead, return the seat so that the LocalScript can sit the player in the seat.
Client Code:
local seat = game.ReplicatedStorage.SpawnCar:InvokeServer(NameOfCar)
seat:Sit(humanoid)
Server Code:
game.ReplicatedStorage:WaitForChild("SpawnCar").OnServerInvoke = function(player,NameOfCar)
local car = game.ServerStorage.Cars:FindFirstChild(NameOfCar):Clone()
car:SetPrimaryPartCFrame(posa.CFrame)
car.Parent = workspace.Vehicles
car:MakeJoints()
car.Name = player.Name.."'s "..NameOfCar
return car.seat
end