Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Combining two functions into one?

How would I go about merging the deplete() function into the fuel() function where it calls for the deplete() function to run in line 6?

local fuelFull = true
local started = false

function fuel()
		if fuelFull == true and started == false then
			deplete()
			print 'STARTING DEPLETING'
		elseif fuelFull == false then
			print 'EMPTY'
		end
end

		
function deplete()
	started = true
	print 'DEPLETING'
	while true do
	script.Parent.FuelValue.Value = script.Parent.FuelValue.Value -1
	wait (.1)
	if script.Parent.FuelValue.Value <15 and script.Parent.FuelValue.Value >0 then
		print 'LOW FUEL'
	elseif script.Parent.FuelValue.Value >15 and script.Parent.FuelValue.Value >0 then
		print 'SAFE'
	elseif script.Parent.FuelValue.Value <15 and script.Parent.FuelValue.Value >-1 then
		print 'EMPTY'
		fuelFull = false
		started = false
	end
	end
end

script.Parent.Touched:connect(fuel) 


2 comments

0

Have you tested this? It looks fine to me.

0

I have tested it withing a much, much larger script and something about it being in two different functions causes a part of the larger script to partially break.

1 answer

Try re-ordering when you declare functions. Declare the deplete function before declaring the fuel function.

2 comments

0

How would I do that? To me it looks like it needs to be in this order.

0

It's easy. Just copy paste the deplete function behind the fuel function. What you're doing is you're using deplete() before it's declared, so it results in an error.

This discussion is preserved as it was. New answers, comments, and votes are closed.