How do I make a car spawner that spawns a car right in front of a player?

Hello, I am hoping to make a car spawner that will spawn a car in front of the player.
Basically, I am making a storm-chasing game called ‘Aerial’ and it needs a car spawner for its storm-chasing cars.

The problem is I actually suck very bad at scripting, and I try to do something more erm - simple.

I put the car in ServerStorage, and in my car spawner script I make the car’s parent workspace, then its position the player.
But I had no luck, and it doesn’t work.

What do I do?

(Yes, I know this is probably a dumb post.)

1 Like

First, try putting the car in ReplicatedStorage instead of ServerStorage. If it doesn’t work, then try the following:

  1. Place the car model in ReplicatedStorage;
  2. Create a RemoteEvent in ReplicatedStorage named “SpawnCar”;
  3. Create a new LocalScript on a TextButton located in StarterGui/ScreenGui;

:red_circle: The idea above is to create a button on the player’s screen that, when clicked, will spawn a new car.

  1. In the LocalScript, add the following script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SpawnCarEvent = ReplicatedStorage:WaitForChild("SpawnCar")

local Button = script.Parent

Button.MouseButton1Up:Connect(function()

	SpawnCarEvent:FireServer()
end)

:red_circle: Call the SpawnCar event so that the server can spawn a new car.

  1. In ServerScriptService, add a script that listens for the SpawnCar event and spawns a new car;"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Car = ReplicatedStorage:WaitForChild("Car")
local SpawnCarEvent = ReplicatedStorage:WaitForChild("SpawnCar")

local SpawnDistance = 20

SpawnCarEvent.OnServerEvent:Connect(function(Player)
	local Character = Player.Character
	local Position = Character:FindFirstChild("HumanoidRootPart").Position
	local Direction = Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector
	local CarSpawnPosition = Position + Direction * 20

	local newCar = Car:Clone()
	newCar.Parent = workspace
	newCar:MoveTo(CarSpawnPosition)
end)

I hope this can help you, but remember, these scripts only spawn the car at a certain distance from the player without considering other factors like orientation and spawn time.

1 Like

Alright, I’ll try this tomorrow.

Trying it!

3 0 C H A R S M I N I M U M

Thank you! This worked, I will manually have to write some code to make it ya know… not stack on each-other and spawn on roofs if close enough!

But this is perfect! Thank you so-so much for the help, Really appreciate it!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.