Make power bar ignore starting power?

I’m working on a soccer game and when a player charges their power up to kick a ball, it doesnt start from 0, it has a starting value, like 35 for example. The problem is that I don’t want my power bar to show that it starts from 35, I want to make my power bar look as if it was starting from zero. Here is my current code.

if input.UserInputType == Enum.UserInputType.MouseButton1 then
		isMouseClicked = true
		power = 35 -- This is my starting power
		ToolController:setUsing(true)
		ToolController:setCharging(true)
		ToolController:enablePowerBar(true)
		
		while isMouseClicked and ToolController:isCharging() do
			power = math.min(power + 1, MAXIMUM_POWER)
			ToolController:updatePowerBar(power/MAXIMUM_POWER) -- Update power bar, power/max power 
			task.wait(.025)
		end
	end

In this video, you can see how the power bar starts in the middle.
fabd43eeccb5e1d19531e14ef65b5616

Try ToolController:updatePowerBar((power - 35)/MAXIMUM_POWER)

1 Like

If you want your power bar to start at 0, use 35 as the offset amount and have another variable to determine how much power has been charged:

local startingPower = 35 --> base power
local maximumIncrease = MAXIMUM_POWER - startingPower --> max amount to increase by

local chargeAmount = 0
while isMouseClicked and ToolController:isCharging() do
    increaseAmount = math.min(power + 1, maximumIncrease)
    ToolController:updatePowerBar(chargeAmount / maximumIncrease)
    task.wait(.025)
end

local totalPower = startingPower + increaseAmount
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.