How to keep spawning vehicles without deleting others?

(Video is shown on the very bottom)
I want Player2 to spawn vehicles without deleting Player1’s vehicle, I tried looking for devforum but couldn’t find a solution because of my poor knowledge in scripting, what lines of codes should I add in order to achieve Player2 to spawn vehicles without deleting Player1’s vehicle?

I got the model in Toolbox https://create.roblox.com/marketplace/asset/8214626878/Urbanmove-Spawner

debounce = false
regen = {}

local regenTime = 20
local maxCount = 4

local guiTextLabel = script.Parent.GUI.TextLabel

for i,v in pairs(script.Parent.Parent.Original:GetChildren()) do
	if v ~= script.Parent then
		table.insert(regen,v:clone())
		v:Destroy()
	end
end

script.Parent.Touched:connect(function(hit)
	if hit.Parent ~= nil then
		if game.Players:playerFromCharacter(hit.Parent) ~= nil and (not debounce) then 
			debounce = true
			if (not script.Parent.Parent:FindFirstChild("Copies")) then
				local backup = Instance.new("Model", script.Parent.Parent)
				backup.Name = "Copies"
			end
			
			local copies = script.Parent.Parent.Copies:GetChildren()
			local count = #copies
						
			if (count >= maxCount) then
				guiTextLabel.Text = "Max # of this object reached!"
				script.Parent.BrickColor = BrickColor.Red()
				wait(2)	
				guiTextLabel.Text = "Touch to regen!"
				script.Parent.BrickColor = BrickColor.new(104)
				debounce = false
				return
			end
			
			for a,b in pairs(copies) do
				if (b:FindFirstChild("Driver")) then
					if ((b.Driver.Position - script.Parent.Position).magnitude < 60) then
						guiTextLabel.Text = "Spawner blocked! Object too close!"
						script.Parent.BrickColor = BrickColor.Red()
						wait(2)	
						guiTextLabel.Text = "Touch to regen!"
						script.Parent.BrickColor = BrickColor.new(104)
						debounce = false
						return
					end
				else
					b:Destroy()
				end
			end
			
			for a,b in pairs(regen) do
				local c = b:clone()
				c.Parent = script.Parent.Parent.Copies
				pcall(function() c:MakeJoints() end)
			end
			
			script.Parent.BrickColor = BrickColor.new(26)
			local timer = regenTime
			while (timer > 0) do
				timer = timer - 1
				guiTextLabel.Text = "Regen in "..timer.." seconds."
				wait(1)	
			end
			guiTextLabel.Text = "Object Spawner"
			script.Parent.BrickColor = BrickColor.new(104)
			debounce = false
		end 
	end 
end)

1 Like

I haven’t thoroughly read through the code, but try deleting the else statement and ‘b:Destroy()’.

1 Like

thank you so much for this !! :grinning:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.