script.Parent.MouseButton1Click:connect(function() local player = game.Players.LocalPlayer local car = game.Lighting.CarOne:Clone() if car ~= nil then car:MoveTo(player.Character.Head.Position) end end)
Since this is a LocalScript, the car will be spawned on the players head, and they only will be able to see it, so you will need two scripts. Having that in mind you will need to have a Remote Event to communicate between the scripts(one server script and a LocalScript), so you go to ReplicatedStorage and add a RemoteEvent in there; you could also name it CarSpawnEvent or something. Now that we have a RemoteEvent, you can add a LocalScript to the button:
--LocalScript --Variables local ReplicatedStorage = game:GetService('ReplicatedStorage') local CarSpawnEvent = ReplicatedStorage:WaitForChild('CarSpawnEvent') --Code script.Parent.MouseButton1Click:Connect(function() CarSpawnEvent:FireServer() --Used to send a message to the server from a client end)
Now put a server script in Workspace, or ServerScriptStorage and write this in it:
--Script: --Variables local ReplicatedStorage = game:GetService('ReplicatedStorage') local CarSpawnEvent = ReplicatedStorage:WaitForChild('CarSpawnEvent') local Lighting = game.Lighting local Car = Lighting:WaitForChild('CarOne') --Functions local function onCarSpawn(plr) local cclone = Car:Clone() cclone.Parent = game.Workspace --To set the parent to workspace cclone.Position = plr.Character.Head.Position + Vector3.new(3,3,3) --So the car doesnt spawn ON the players head. end --Code CarSpawnEvent.OnServerEvent:Connect(onCarSpawn) --To connect to the function if the RemoteEvent has been fired by the client.
You could also name the script something like 'CarSpawn' so you dont mix it up with other scripts.