Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Stop bugging car spawner?

Hey! Currently, I want to make a car spawner, I have done the main script but a player can press it again and then there are two cars in the same position which is making the game bug. Here is my current code:

button = script.Parent

button.MouseButton1Down:Connect(function()
	local car = game.ServerStorage["308"]
	local carclone = car:Clone()
	carclone.Parent = game.Workspace
end)

1 answer

Well you could check the Position of the previously spawned car. If it is not moved then do not allow the new car to be spawned. Something like this, i think.

button = script.Parent
local previouscar = nil
local previouscarposition = nil
button.MouseButton1Down:Connect(function()
	if not (previouscar and previouscar.PrimaryPart.Position == previouscarposition) then
    		local car = game.ServerStorage["308"]
    		local carclone = car:Clone()
   		carclone.Parent = game.Workspace
 		previouscar = carclone
 		previouscarposition = carclone.PrimaryPart.Position
	end
end)

10 comments

0

Sorry didnt work

0

What is the problem that comes up?

0

Nope it was me thank you so much!

0

Glad I could help

0

Hello i needed to remove the acceptance, once I spawn a car, no other cars will spawn so no it doesnt work

0

is there any error?

0

 Workspace.Part.SurfaceGui.Frame.TextButton.Script:5: attempt to index nil with 'Position'

0

Are you sure you have set a primary part for the model?

0

How do you do that lol?

0

Click on the model, Click on the Blank Space in front of Primary Part and then Click on the Part you want to make Primary Part

This discussion is preserved as it was. New answers, comments, and votes are closed.