So I was working on a stats multiplier based on score you get in the game and for some reason the multiplier text glitched and it started showing a lot of decimals instead of showing the exact number I wanted it to show.
A comparison between stats without the multiplier and stats with the multiplier
The original multiplier at the bottom right corner
Rocket Cooldown text changed as well even though it’s not supposed to change
Some stuff that you need to know:
The multiplied stats are based on the NumberValues (base stats) in player stats and are multiplied in the local script that changes the text to all stats in the Total Stats frame.
The score goal also became decimals for some reason and that is NOT supposed to happen.
Please help!
EDIT: If you need to see the script for the TextLabels in the Total Stats frame tell me.
So I have this local script for tracking the score left until my multiplier increases.
local Goal = 1
local Base = 1000
script.Parent.Text = (Base * Goal) - (game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("score").Value).." Score"
game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("score"):GetPropertyChangedSignal("Value"):Connect(function()
if (Base * Goal) - (game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("score").Value) <= 0 then
game.ReplicatedStorage.Events.Game.IncreaseMulti:FireServer(--[[Secret string password]]--)
Goal += 1
Base *= 1.125
if (Base * Goal) - (game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("score").Value) <= 0 then
Base = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("score").Value + 1000
script.Parent.Text = (Base * Goal) - (game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("score").Value).." Score"
else
script.Parent.Text = (Base * Goal) - (game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("score").Value).." Score"
end
else
script.Parent.Text = (Base * Goal) - (game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("score").Value).." Score"
end
end)
I know it’s quite weird but it fixes a problem with negative score goals.
As you can see it fires an event secured with a password to a server script.
This is the server script:
game.ReplicatedStorage.Events.Game.IncreaseMulti.OnServerEvent:Connect(function(Player,password)
if password ~= --[[Secret String Password-]] then return end
Player:WaitForChild("player stats"):WaitForChild("multiplier").Value += 0.025
end)
As you can see it’s supposed to increase the multiplier by 0.025 every time this event is fired.
The multiplier of course starts at 1.
theres not really a fix, but you can keep the value to only a few decimal places by doing this:
local Places = 3
local function Floor(n,p) -- n is a number, p is the place
return math.floor(n * 10^p) / 10^p
end
print(Floor(15.235536363424,Places))
use the function on the already calculated values, set the place however you like, depends on your game if decimals are extremely important. this function can solve the imprecision, but it doesn’t fix it, it just hides the imprecision
The decimals happening here is because of floating point numbers. If you want to fix this, you can use math.floor(number) to remove the decimals.
local number = 3.555555
print(math.floor(number)) -- prints 3
Though, keep in mind math.floor(number) essentially removes the decimals only. If you want the number to round to the nearest number instead, use math.round(number):
local number = 3.555555
print(math.round(number)) -- prints 4
To approximate the decimals instead of completely removing them, you can use string.format to format the number, for example:
local number = 3.555555
local places = 3
print(string.format("%." .. places .. "f", number)) -- prints 3.556