Hello there, RobertTBS here! Today I’m going to show you how to create a gas station that Actually refills gas!
For this to work we need this place:
GasTesting.rbxl (154.6 KB)
This is the place where I started the scripting on it.
Make sure you enable ProximityPromt in beta features
Open up the place by pressing ctrl-o in studio. You will see 3 vehicles and 3 colored blocks.
There are 3 different vehicle types. Diesel, Gas, and Zap. (Zap is a shortened way I use for electric.
Red is normal gasoline
Green is diesel
Blue is electric.
Look inside of one of the pumps. you will see something sort of like this:
Show code
wait(.5)
script.Parent.Triggered:Connect(function(Player)
if Player.Character.Humanoid.Sit == true then
print("Player sitting")
if Player.PlayerGui["A-Chassis Interface"].Car.Value.Type.Value == "Zap" then
Player.PlayerGui["A-Chassis Interface"].Car.Value.Fuel.Value = 1
end
else
print("Not sitting!")
end
end)
Changing the Car.Value.Type.Value == " " to “gas”, “diesel”, or “zap”, depending on the type of vehicle you would like to charge/refill.
Changing the Car.Value.Fuel.Value = to a different number changes how full the vehicle will get.
Now we’re going to look into the vehicles. Ignore the main localscript, and we’re going to go to the thing that makes this all work.
Show code
local maxFuel = 1 --Liters of fuel
local car = script.Parent.Parent
local fuel = car:FindFirstChild('Zap') or Instance.new('NumberValue', car)
fuel.Name = 'Fuel'
fuel.Value = maxFuel
local car = script.Parent.Parent
local isgas = car:FindFirstChild('Type') or Instance.new('StringValue', car)
isgas.Name = 'Type'
isgas.Value = "Zap"
script.Parent.OnServerEvent:Connect(function(plr, amount)
if amount then
fuel.Value = fuel.Value - amount
else
script.Parent:FireClient(plr, fuel.Value)
end
end)
fuel.Changed:Connect(function(val)
if car.DriveSeat.Occupant then
script.Parent:FireClient(game.Players:GetPlayerFromCharacter(car.DriveSeat.Occupant.Parent), fuel.Value)
end
end)
maxFuel changes the max amount of fuel, as you might guess.
isgas.Value = “” changes the type, (gas, diesel, zap)
The rest is for transferring to the main localscript.
Thank you for reading this! Make sure to ! See you next time!