Vehicle Spawner Problem

Hello, I am making a Vehicle Spawner system but I am stuck in 2 things, The Spawner GUI and be cloned many times by clicking a box again, and that Vehicles would have the chance to spawn ontop of each other.

local GUI = Parent["Car Spawn"]

local function spawn(player)
	local a = GUI:Clone()
	a.Parent = player.PlayerGui	
end	

Parent.ClickDetector.MouseClick:Connect(spawn)

here’s the simply script for the GUI so far,

To solve the GUI a problem, you should make like a bool value to check if the player has the GUI or not. Secondly, to solve the car problem, just make them spawn next to each other.

You need to look if the vehicle is spawned already do

local vehiclespawned = false

while wait(1) do
	if vehiclespawned == true then
		print("Vehicle is already spawned ")
	elseif vehiclespawned == false then
		-- Spawn The Vehicle
	end
end

you also need to set the
local vehiclespawned = false
set it to true if it get’s spawned

If you are making it with a button you need to do this

local vehiclespawned = false
local Button = script.Parent

Button.MouseButton1Click:Connect(function()
	while wait(1) do
		if vehiclespawned == true then
			print("Vehicle is already spawned ")
		elseif vehiclespawned == false then
			vehiclespawned = true
			-- Spawn The Vehicle
		end
	end
end)

Nice, but how do I make sure the Vehicle won’t be spawned by someone else does, or to respawn the Vehicle using the same GUI?

You can try 3 thing’s

  1. Try making if the vehicle goes away from the region where it spawns there can be a second vehicle spawned

  2. You can make the vehicle spawn infront of a player by looking to the possition of the player and adding 10 studs infront of the player

  3. Make your car’s collide

That was my Original plan but I kinda got confused on how to work the Regions, since i used touched and touch ended events.

I don’t know how to do this so what my idea is

set a part infront of the vehicle or arount it if the vehicle touched it there can spawn an other vehicle.

so you need to set the

local vehiclespawned = false

back to false and not true cause it will get true when a vehicle is spawned
so when the vehicle touched the part it will set it to false so that an other vehicle can spawn back again.

I just came up with an idea if you have the part around it and you have make in collide make it when a player touched it cause ye the player needs to be in the vehicle than it will set it back to false

so that will work fine but make sure to set a delay when a player did touch it so there are no vehicles spawning on top of each other

I hope i did help you with all my information!

what happens if by some chance the Player decides to just stay in the area?

nothing cause the player did never touch the part so no vehicle can respawn again but u can create if the player did not touched the part after 30 seconds the vehicle will delete

1 Like