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

Can Someone help me with my obby percent indicator?

The code is working fine however when I tested it I was on stage 1 and the percent indicator looking like this Progress: 0.14285714285714% but I need help on how would I shorten it to 0.14% instead of 0.14285714285714%.

edit: I want it to change the no. removing this 1.00 and making it 1 however I can't understand how to change it basically I want to remove the decimal point if it is a whole no. and if it has a decimal it will automatically have a decimal point

edit2: NVM It works now

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local Stagelabel = script.Parent.Parent.Stages
local Progresslabel = script.Parent.Parent.Progress
local bar = script.Parent.Bar
local MaxStage = 700

while wait(0.01) do
	local Percent =  game.Players.LocalPlayer:WaitForChild("leaderstats").Stage.Value / MaxStage * 100
	bar.Size = UDim2.new(1/(MaxStage/leaderstats.Stage.Value), 0, 1, 0)
	Stagelabel.Text = "Stage: "..game.Players.LocalPlayer:WaitForChild("leaderstats").Stage.Value

	for i = 0,100,1 do
		if Progresslabel.Text ~= "Progress: "..i..".00%" then
			Progresslabel.Text = ("Progress: %.2f%%"):format(Percent)
		end
	end
	for i = 0,100,1 do
		if Progresslabel.Text == "Progress: "..i..".00%" then
			Progresslabel.Text = ("Progress: %.0f%%"):format(Percent)
		end
	end
end


1 comment

0

Use math.floor. That will round it off to the nearest whole number.

1 answer

✓ Accepted answer

You can use string.format()

An example there would be.

local number = 0.14285714285714
local str = ("Progress: %.2f%%"):format(number)
print(str) --// "Progress: 0.14%"
  • %.2f is the patern (just matches a float with 2 decimal points)
  • %% just double % escapes one of them so it shows a %.

Sources

Notice I put Printf stuff there, yes it's C++ but C++'s Printf is similar to Lua's string.format.


If this helped you don't forget to mark it as an answer!

4 comments

0

Quick question how would I remove the decimals if its a whole number?

0

Please help I Don't want to see it as 100.00%

0

You would have to check if it is 100%, and then use local str = ()

0

You would have to check if it is 100%, and then use ("Progress: %d"):format(number)

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