You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? A fuel system where if your fuel goes to 0, you can’t control the boat
What is the issue? The boat can still be controlled
What solutions have you tried so far? ChatGPT and my brain
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Heres the code snippet.
local function fuelFinished()
if currentFuel.Value == 0 then
runService:UnbindFromRenderStep("DriveBoat")
seat.ThrottleFloat = 0
end
end
runService.Stepped:Connect(updateBoatUI)
runService.Stepped:Connect(fuelFinished)
while true do
task.wait()
if currentFuel.Value ~= 0 then
runService:BindToRenderStep("DriveBoat", 1, DriveBoat)
end
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
The issue with your code is the fact that you are constantly binding new function to BindToRenderStep because you are not checking if it exists already.
Your implementation of BindToRenderStep is wrong. Although it will work, the priority you are setting is super low (Player input is 100).
What you could do instead is:
local boatControlConnection
local function fuelFinished()
if currentFuel.Value == 0 then
boatControlConnection = boatControlConnection:Disconnect()
seat.ThrottleFloat = 0
end
end
runService.Stepped:Connect(updateBoatUI)
runService.Stepped:Connect(fuelFinished)
while task.wait() do
if currentFuel.Value ~= 0 and not boatControlConnection then
boatControlConnection = runService["Heartbeat"]:Connect(DriveBoat)
-- //Use Heartbeat for stuff which will directly work with environment(physics, etc)
-- //For UI, Camera control use RenderStepped
end
end