I was making a one car only vehicle spawner script and was wondering how you run code if something doesn’t exist
system = script.Parent
model = system.Station --
backup = model:Clone()
regen = system.Regen
function checkRegen()
if script.plr.Value == nil then
if regen.Value == 1 then
model:remove()
wait(1)
model = backup:Clone()
model.Parent = system
model:MakeJoints()
end
end
end
regen.Changed:connect(checkRegen)
Code: The one that changes the value
button = script.Parent
regen = button.Parent.Regen
local debounce = false
function onTouch(hit)
local h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil and debounce == false then
script.Parent.Parent.Script.plr.Value = hit.Parent.Vehicle
debounce = true
button.BrickColor = BrickColor.Black()
regen.Value = 1
wait(1)
regen.Value = 0
wait(5)
button.BrickColor = BrickColor.new(104)
debounce = false
end
end
button.Touched:connect(onTouch)
so to be specific I abandoned all that code since it’s meant to work like it worked in V.4 which it deletes it when the vehicle seat is touched and also makes it so much less labor has to be done to convert existing vehicle spawners by just putting the code in the seat.
script.Parent.Touched:Connect(function(hit)
local h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil then
if hit.Parent:FindFirstChild("Vehicle") then
script.Parent:Destroy()
end
end
end)
So, when someone spawns a vehicle I want it to make sure they don’t have 2.
So if they have no other vehicles it allows them in the seat, if they have 2 vehicles it deletes the car.
The vehicle gets put in the workspace plr model btw