Hello everyone, I’m scripting a vehicle spawn system, and inside the StarterCharacter is a boolean called “HasVehicle”. Basically, when the player spawns a vehicle it turns this value to true, so then if they try to spawn another vehicle they cannot. This is the structure:
if workspace[namedplayer].HasVehicle.Value == true then
--how do i end it here before it goes to the else statement
else
sound:Play()
gui.ScrollingFrame.Visible = false
button.Visible = true
local vehicletospawn = v.Vehicle.Value
local spawnedvehicle = vehicledir[vehicletospawn]:Clone()
spawnedvehicle.Parent = game.Workspace
spawnedvehicle:PivotTo(gui.Parent.Parent.SpawnPos.CFrame)
end
I want to know how I can end the if statement if the value is set to true.
local a = true
if a then
--//a is true, so this code block will execute, the else statement only executes if this condition is NOT true
else
--//The else clause only executes if the expression above is not evaluated to true
end
If you only need to execute some code if a player’s HasVehicle value is false, then change your condition testing if the value is false instead of true.
if not workspace[namedplayer].HasVehicle.Value then
sound:Play()
gui.ScrollingFrame.Visible = false
button.Visible = true
local vehicletospawn = v.Vehicle.Value
local spawnedvehicle = vehicledir[vehicletospawn]:Clone()
spawnedvehicle.Parent = game.Workspace
spawnedvehicle:PivotTo(gui.Parent.Parent.SpawnPos.CFrame)
end