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

Checking if you have the car already?

I am making a game that you need to check if you have already spawned that car, meaning if you already have a car spawned, you cannot spawn it again until it is removed. How could you check and see?

Here's what I have and I know this is a terrible way of doing it.

--Made by wattleman

local serv = game.ReplicatedStorage
local cc = serv:WaitForChild("CrudCar")

function spawnNew()
	cc:clone()
	isOneThere()
	if v == true then
	else
		cc.Parent = game.Workspace
		cc.Position = Vector3.new(-101.356, 35.503, 131.955)
		cc.Rotation = Vector3.new(-0, 0.001, 0)
	end
end

function isOneThere()
	local search = game.Workspace:GetChildren()
	for _,v in ipairs(search) do
		if v.Name == "CrudCar" then
			local vs = v:WaitForChild("VehicleSeat")
			if vs then
				if vs.Position.Changed then
					return true
				else
					return false
				end
			end
		end
	end
end

script.Parent.Touched:connect(spawnNew)

1 answer

Hmm. I know you can clean this up a little, for sure.

You could introduce a value to the car indicating the spawner, and have all cars in a model. Then you can loop the model's children and check for the spawner in the meantime.

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