Help needed with car spawner

Hello!

I am creating a car spawner and have the basics working. I want to make it to where the player can only have one car spawned at a time, and if they already have a car spawned it’ll delete that one if the spawn the other. As I am not yet a competent enough scripter to figure this out on my own I resorted to youtube, but couldn’t find anything helpful. If you can help, much thanks! Here’s some pictures:



Thanks!

How do you get Spawner Gui do you clone it?

You can try this didn’t test it

script.Parent.MouseButton1Click:connect(function()
local Player = script.Parent.Parent.Parent.Parent.Parent.Parent --Change this it should say Data Model in the end
local Model = game:GetService(“ServerStorage”):WaitForChild(“Policecar”)

if Player:IsA("Player") and not workspace:FindFirstChild(Model.Name.."'s Car") then
	local Clone = Model:Clone()
	
	Clone.Name = Player.Name.."'s Car"
	Clone.Parent = workspace
	Clone:MakeJoints()
end

end)

1 Like

Thanks! I’ll try it and if it works I’ll give you the solution. If not I’ll get back to you!

Change the car’s name to plr.Name…“car” and then whenever you want to spawn a car, check if this name already exists. If it does, delete it then clone a new car and name it to plr.Name…“car”.

1 Like

i made typo

if Player:IsA(“Player”) and not workspace:FindFirstChild(Player.Name…"'s Car") then
local Clone = Model:Clone()

Clone.Name = Player.Name.."'s Car"
Clone.Parent = workspace
Clone:MakeJoints()

end

1 Like

It should say Player.Name not Model.Name

So your code didn’t fully achieve what I was hoping to get, however it helped me find the basics of what I needed. Thanks for that!
You also forgot a “end)” for future reference. Not having it broke the code.
Here’s the final code:

script.Parent.MouseButton1Click:Connect(function()
	local Player = script.Parent.Parent.Parent.Parent.Parent.Parent
	local Model = game:GetService("ServerStorage"):WaitForChild("Policecar")

	if Player:IsA("Player") and not workspace:FindFirstChild(Player.Name.."'s Car") then
		local Clone = Model:Clone()
		Clone.Name = Player.Name.."'s Car"
		Clone.Parent = workspace
		Clone:MakeJoints()
	else
		game.Workspace:FindFirstChild(Player.Name.."'s Car"):Destroy()
		local Clone = Model:Clone()
		Clone.Name = Player.Name.."'s Car"
		Clone.Parent = workspace
		Clone:MakeJoints()
	end
end)