I want to make a car spawner for my game, so the player can easily go about the map, but for some reason it won’t work.
local car = game.Workspace.Cartemplate
script.Parent.MouseClick:Connect(function(player)
local carClone = car:Clone()
carClone.Parent = game.Workspace
print("Success!")
end)
I tried to use the AI Assistent to help me, but it still won’t work.
It doesn’t work anymore? But I swear this worked yesterday…
local car = game.ServerStorage.Vehicles.Sudan
local OFFSET = Vector3.new(20, 0, 0)
local player = game.Players.LocalPlayer
local character = player.Character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local targetPosition = humanoidRootPart.Position + OFFSET
script.Parent.MouseClick:Connect(function(player)
local carClone = car:Clone()
carClone.Parent = game.Workspace
carClone.CFrame = CFrame.new(targetPosition)
print("Success!")
end)
Judging off the fact you’re using MouseClick and LocalPlayer I can only assume you’re running this on the client.
The client doesn’t have access to ServerStorage, so it’s not able to access the car.
The solution would be to either store the car in the ReplicatedStorage, or fire a remote event that clones the car on the server when the player clicks.