I am new to scripting so this might be pretty easy to do but I made a script that when you walk on a button it spawns a car, however the only problem is that if you don't move the car then walk on the spawn button again it will spawn inside of it and glitch it out. So would anyone know how to make a script to avoid this from happening
Most people will usually make it so the car will get destroyed when you press the button, to do this, I would give the car a second GLOBAL VARIABLE after it gets cloned and put in the proper place.
Now what is a global variable you may ask? Well, a global variable is a variable that is defined in the core of the script, like when you get the player service, or define a part at the beginning of a script. What you may not know about these, though, is that you can make them have no value, like this:
local OldCar
This will make a new variable called OldCar with no value. Why is this important, you may ask? Well, setting the clone you made to OldCar will make it so that there is a car you can, well, destroy after you spawn the next one in, so at the top of your script, make a line to destroy the car, as so:
OldCar:Destroy()
This should make it so that the old car will be destroyed when you spawn the new one in. I hope this helped!
heres the script it is located inside the regen button
model = script.Parent.Parent regen = script.Parent--Indicates that the script interacts with the model the button is grouped with. backup = model:clone() enabled = true function regenerate() model = backup:clone() model.Parent = game.Workspace model:makeJoints() script.Disabled = true script.Parent.BrickColor = BrickColor.new(26)--Black wait(10)--Change this number to change the time in between regenerations via the button, in seconds.. script.Parent.BrickColor = BrickColor.new(104)--Purple script.Disabled = false end function onHit(hit) if (hit.Parent:FindFirstChild("Humanoid") ~= nil) and enabled==true then regenerate() end end script.Parent.Touched:connect(onHit)