If I get you correct, you want a script that tells you how much you have completed an obby?
Thinking that percentage can’t go above 100% (If we don’t mean that you can complete more than the stage itself, which shouldn’t be possible) you should be able to get the percentage by dividing the Players Value with the Maximum Value.
Example Script:
local PlayerValue = 10
local MaxValue = 230
local Text = script.Parent.Text
local Percentage = (PlayerValue / MaxValue) * 100
Text = "The Player has completed ".. math.floor(Percentage) .. " of the Obby!"
If you want this to stay up to date, just put it in a while true do loop like this:
while true do
wait()
local PlayerValue = 10
local MaxValue = 230
local Text = script.Parent.Text
local Percentage = (PlayerValue / MaxValue) * 100
Text = "The Player has completed ".. math.floor(Percentage) .. " of the Obby!"
end
EDIT: Just saw that Blokav above wrote something similair while I was typing. It also works
Busy loops like these are not good practice; it’s preferable OP updates based on some event, whether manually triggered or through a Roblox connection.
Just for fun, you can use string’s format function too:
local text = ("%i%% of obby completed!"):format(value / maxValue * 100)
The “%i” is replaced with an integer number, thus a non-integer will just get its decimal cut off (essentially flooring the value). The “%%” just escapes the “%” so it will appear as-is and not get formatted.
In this script you are actually initializing “StageText” and “Completed” as string variables; you can’t directly reference properties of instances like what you seem to be trying to do.
Try initializing them as this:
local StageText = script.Parent.Stage
local Completed = script.Parent.Completed
Then update them like this:
StageText.Text = "Stage: "..StageValue
local Percentage = math.floor(StageValue / MaxValue * 100)
Completed.Text = Percentage.."% of obby completed"
Could you show the exact line of code where you perform this calculation in that it results in a negative value? This should not be the case when you’re offsetting the value.
Be sure to also include updated code lines when something doesn’t work so we can build off your progress and see what the issue may be, thus allowing us to better help you.
Your order of operations is starting to look confusing. I like to organize these kinds of expressions with parentheses. It ensures that operations are done in the order they are supposed to and also makes it more readable.