How to limit one car a person, if attempted it despawns last and spawns new

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to achieve this simple car spawner to limit to one vehicle a person, and if the person already spawned a vehicle then tries to spawn another. It shall despawn the last one, and respawn a new one.
  2. What is the issue? Include screenshots / videos if possible!
    I can’t figure out how to produce what I want.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes I did, the solutions I saw did not help me with my script.
		local Mod = game.ServerStorage.Cars.MRAP
		local clone = Mod:clone()
		clone.Parent = workspace

Mainly I couldn’t find out how to detect if the player already spawned a car.

You probably want to have a local script which checks when a vehicle is spawned.

Then you will want to fire a remote event which gets handled by the server (where the vehicle will eventually be spawned).

One idea could be to have a dictionary in the server script (which uses key, value pairs), maybe you could store players and their spawned vehicle -nil if they haven’t got a spawned vehicle.

Then all you would have to do is whenever a player attempts to spawn a vehicle, do a check to see if they currently have a spawned vehicle in this dictionary and destroy it if so and spawn the new one.

1 Like