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

How do i make a Maximum amount for a number?

With the help of scripterhelpers I found out how to make a energy system. But i have no clue how to make a maximum number so that players cant go over the energy system's gui. Here is the part of the script

local player = game.Players.LocalPlayer
local Gui = script.Parent
local EnergyValue = script.Parent.EnergyValue
local MaxEnergy = script.Parent.MaxEnergyValue

		game:WaitForChild(player)
Gui.Size = UDim2.new((EnergyValue.Value/MaxEnergy.Value),0,0,50)
EnergyValue.Changed:connect(function()
	Gui.Size = UDim2.new((EnergyValue.Value/MaxEnergy.Value),0,0,50)
	
	
end) 
while true do --here is the main part of the script
	wait(0.1)
if EnergyValue.Value > MaxEnergy.Value then break end

end

1 comment

0

Try only enabling this for when the energy is less then the max (Energy.value < Max.value) Instead of trying to fix it after it passed thw maximum.

2 answers

You have the right idea. But all that happens with if EnergyValue.Value > MaxEnergy.Value then break end is you exit that arbitrary infinite loop. Nothing changes. You would want to call script.Destroy() , or disconnect the changed event. Even better is to simply do this check inside the changed function.

local player = game.Players.LocalPlayer
local Gui = script.Parent
local EnergyValue = script.Parent.EnergyValue
local MaxEnergy = script.Parent.MaxEnergyValue

        game:WaitForChild(player)
Gui.Size = UDim2.new((EnergyValue.Value/MaxEnergy.Value),0,0,50)
EnergyValue.Changed:connect(function()
    if EnergyValue.Value < MaxEnergy then
        Gui.Size = UDim2.new((EnergyValue.Value/MaxEnergy.Value),0,0,50)
    end
end) 

say m is the int and max is the max number the max number is 10 then

local m = 1
local max = 10

if m.Value > max.Value the break end

1 comment

0

The Gui is still going past the border

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