I am making a system that spawns a player's chosen vehicle into the game. It also forces the player to sit in the vehicle.
(You may need to click view source to see the full script. Some of it may be cut off.)
Here is the local Script in StarterPlayerScripts:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Cars = ReplicatedStorage.PlayerCars
ReplicatedStorage.PlayerCarEvents.SpawnCar.OnClientEvent:Connect(function(Car, Position)
local playerCar = Cars:FindFirstChild(Car):Clone()
playerCar.Parent = workspace
playerCar:MoveTo(Position)
game.Players.LocalPlayer.CharacterAdded:Connect(function()
ReplicatedStorage.PlayerCarEvents.SpawnPlayer:FireServer(playerCar.Chassis.VehicleSeat)
end)
end)
Here is the server script in ServerScriptService:
local DataSotreService = game:GetService("DataStoreService")
local PlayerCarDataStore = DataSotreService:GetDataStore("PlayerCar")
local DefaultCar = "Pickup Truck (blue)"
local ReplicatedSotrage = game:GetService("ReplicatedStorage")
local CarSpawns = game.Workspace:FindFirstChild("Track Structures").CarSpawners
game.Players.PlayerAdded:Connect(function(Player)
for i, carSpawn in ipairs(CarSpawns:GetChildren()) do
if carSpawn:GetAttribute("Used") == false then
ReplicatedSotrage.PlayerCarEvents.SpawnCar:FireClient(Player, PlayerCarDataStore:GetAsync(Player) or DefaultCar, Vector3.new(carSpawn.Position.X, carSpawn.Position.Y + 15, carSpawn.Position.Z))
carSpawn:SetAttribute("Used", true)
game.ReplicatedStorage.PlayerCarEvents.SpawnPlayer.OnServerEvent:Connect(function(Seat, Character)
Seat:Sit(Player.Character:WaitForChild("Humanoid"))
end)
break
end
end
end)
In summary, when the player spawns the server tells the client to spawn the player's car and all the information it needs to spawn it. That part works. But then the client tells the server to force the player to sit in the seat of the car (line 9 of the local script) but the sever keeps outputting the error: 'Sit is not a valid member of Players.InsertThePlayersUsernameHere'. Can somebody help me fix this error?

1 comment
Thank you so much.