Hello, I'm making a vehicle game and I have it so once a player joins the game it fires a remote event that spawns a car and teleports that player to the car but if someone joins after me they cannot see my car but instead see me flying around sitting in the air yet I see their car. Is it because they weren't there for when I fired the remote event to spawn my vehicle? or is it a different issue entirely? and can you guys give me any ideas on how to fix it?
Local script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = ReplicatedStorage:WaitForChild("SpawnCar") remoteEvent:FireServer()
Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = ReplicatedStorage:WaitForChild("SpawnCar") local spawns = workspace.Spawns:GetChildren() local function onCreateCar(player) local randomSpawn = spawns[math.random(#spawns)] print(player.Name, "has requested a vehicle") local car = ReplicatedStorage:WaitForChild("Car") local carClone = car:Clone() car.Parent = workspace car:SetPrimaryPartCFrame(randomSpawn.CFrame) game["Run Service"].Heartbeat:Wait() player.Character.HumanoidRootPart.Position = car.VehicleSeat.Position game["Run Service"].Heartbeat:Wait() car.VehicleSeat:Sit(player.Character.Humanoid) end remoteEvent.OnServerEvent:Connect(onCreateCar)
Use Players.PlayerAdded
instead. Also in lines 13-18, you're using the car from ReplicatedStorage and not the clone itself, that's why not all players can see your vehicle.
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local spawns = workspace.Spawns:GetChildren() Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) local randomSpawn = spawns[Random.new(os.time()):NextInteger(1, #spawns)] print(Player.Name .. " has requested a vehicle") local car = ReplicatedStorage:WaitForChild("Car") local carClone = car:Clone() carClone.Parent = workspace carClone:PivotTo(randomSpawn:GetPivot()) task.wait() Character:PivotTo(carClone.VehicleSeat.CFrame) task.wait() carClone.VehicleSeat:Sit(Character:WaitForChild("Humanoid")) end end)