Car won't spawn

I’m making a GUI car spawner but everytime I click the GUI, it tells me I can’t spawn because the car doesn’t exist in ServerStorage.

Proof car is in server storage:

Screen Shot 2021-09-04 at 7.38.44 PM


Script:

local player = game.Players.LocalPlayer
local db = false
local carLimit = 1
local cars = 0

script.Parent.MouseButton1Click:Connect(function(GetCar)
	if cars < carLimit then
		if db == false then
			if player.Team == game.Teams.FBI then
				db = true
				Mod = game:GetService("ServerStorage"):FindFirstChild("FbiCruiser")
				clone = Mod:clone()
				clone.Parent = workspace
				clone:MakeJoints()
				
				player.Character.HumanoidRootPart.CFrame = clone.DriveSeat.CFrame
				wait(100)
				db = false
			end
		else
			script.Parent.BackgroundTransparency = 0
			script.Parent.BackgroundColor3 = Color3.fromRGB(255,0,0)
			wait(3)
			script.Parent.BackgroundTransparency = 1
			script.Parent.BackgroundColor3 = Color3.fromRGB(255,255,255)
		end
	else
		script.Parent.BackgroundTransparency = 0
		script.Parent.BackgroundColor3 = Color3.fromRGB(255,0,0)
		wait(3)
		script.Parent.BackgroundTransparency = 1
		script.Parent.BackgroundColor3 = Color3.fromRGB(255,255,255)
	end
end)

Error

Players.LMVM2041.PlayerGui.FBICarSpawner.Frame.ScrollingFrame.FBICAR.LocalScript:12: attempt to index nil with 'clone'

It seems you are trying to spawn the car on the client. This will not work because the car won’t get replicated to other clients, and clients do not have access to ServerStorage as it is not replicated to the clients.
Makes sense?

So I can use a remote event and fire it to a server script instead?

Yup, doing that will fix the issue.

2 Likes