I made a spawner, that if you click a button, it spawns a car. But every 1 seocnd, it spawns another one. How do i fix this?

script:

local debounce = false
local plr = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	for i,v in pairs(game.Players.LocalPlayer.Character:GetChildren())do
	if v:IsA("Model") then
	v:Destroy()
	end
	wait(1)
	if not debounce then
			wait()
		 local car = plr.SelectedCar.Value:Clone()
		car.Parent = game.Players.LocalPlayer.Character
		car.Name = plr.Name..("'s Car")
		car:SetPrimaryPartCFrame(plr.Character.Head.CFrame * CFrame.new(0,0,-10))
		car:MakeJoints()
		debounce = true
		wait(1)
		debounce = false
	end
	end
end)

2 comments

0

it spawns one for every child of the players character. try spawning the car outside of the for loop?

0

Then the car will instantly get deleted. i did this to prevent car spawn spamming