This script is for a rocket, it launches upon a RemoteEvent
firing and flies up for 1 second per fuel
. However, during pre-launch, the startup_fuel
function is not working as intended. It does not add the 10 extra fuel
found in the fuel tank.
Explorer:
Script:
local remotes = game.ReplicatedStorage.Remotes
local startup = remotes.RocketStartup
local launched = false
local fuel = 3
local altitude = 0
local usage = 0
function startup_fuel()
for i,v in pairs(script.Parent:GetDescendants()) do
if string.find(v.Name, "Fuel") then
if v:FindFirstChild("Fuel") and v:IsA("NumberValue") then
local f = v:FindFirstChild("Fuel")
fuel += f.Value
print(v.Name.." registered")
end
end
end
end
function startup_engines()
for i,v in pairs(script.Parent:GetDescendants()) do
if string.find(v.Name, "Engine") then
if v:FindFirstChild("Usage") then
engines = v
local u = v:FindFirstChild("Usage")
usage += u.Value
print(v.Name.." registered")
end
end
end
end
function startup_seat()
seat = script.Parent.Seat.Pilot
end
startup.OnServerEvent:Connect(function(plr)
startup_seat()
if seat.Occupant.Parent.Name == plr.Name then
startup_engines()
startup_fuel()
wait(0.5)
launched = true
engines.Base.VectorForce.Enabled = true
while fuel ~= 0 do
fuel -= usage
print(fuel)
wait(1)
end
if fuel == 0 then
engines.Base.VectorForce.Enabled = false
end
end
end)