Gas Station With Refilling Vehicle Scripts

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 :heart:! See you next time!

10 Likes

Could you upload it as a model, I don’t feel comfortable downloading random file’s onto my computer.

2 Likes
3 Likes

The file he sent is a rbxl file type. This means it is for a roblox place. It’s fine if you want the the model but rbxl files are commonly shared to my knowledge in many devforum tutorials.

3 Likes

It’s an Roblox file with Roblox scripts for lua. Very unlikely there is a virus inside of that and with the rbxl or rbxm, it’s fine.

1 Like

This isn’t a tutorial on how to create a gas station, it’s sharing a premade gas station with tips on how to use the file. As such, I have moved this over to Community Resources. Please do keep in mind the difference between the categories is that Community Tutorials shows you how to achieve something on your own in detail, whereas Community Resources is for showcasing and explaining how to use resources you’ve made. You can read more in our category guidelines.

8 Likes