How do I Round Numbers in a Leaderstats Script/Cash Collector?

I’ve looked at a few articles regarding rounding numbers. An older tactic was to use Math.Floor, while others stated that Roblox somewhat recently added a Math.Round() function. I’m trying to make it so that cash in the leaderboard remain as whole numbers without decimals. With all of the multiplying I am using (multiplying your cash by 1.05x when you get a kill, a 1.2x cash if you have premium, etc), it is leading to some undesirably long numbers.

I’m curious which tactic I should use, and how I would even apply it to a script. I can only seem to find people using the command bar printing commands as examples.

This is the leaderstats code

	
	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"
	
	local Cash = Instance.new("NumberValue", leaderstats)
	Cash.Name = "Cash"
	Cash.Value = 0
	
	local Kills = Instance.new("NumberValue", leaderstats)
	Kills.Name = "Kills"
	Kills.Value = 0
	
	local Deaths = Instance.new("NumberValue", leaderstats)
	Deaths.Name = "Deaths"
	Deaths.Value = 0
	
	local OwnsTycoon = Instance.new("BoolValue", Player)
	OwnsTycoon.Name = "OwnsTycoon"
	OwnsTycoon.Value = false
	
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:FindFirstChild("Humanoid")
		
		Humanoid.Died:Connect(function(Died)
			Deaths.Value = Deaths.Value + 1
			local Tag = Humanoid:FindFirstChild("creator")
			local Killer = Tag.Value
			if Tag and Killer then
				Killer.leaderstats:FindFirstChild("Kills").Value = Killer.leaderstats:FindFirstChild("Kills").Value + 1
				Killer.leaderstats:FindFirstChild("Cash").Value = Killer.leaderstats:FindFirstChild("Cash").Value * 1.1
			end
		end)
	end)
end)

This is the part of a script used to give the player cash and multiplies it depending on premium status and gamepass ownership. I’m posting this in case the problem has to be approached from this script, rather than the leaderstats script. Though, my leaderstats script also has a multiplying function for getting a kill, so I’m curious if I have to add something to the end of each multiplying function.

MainItems.CashButton.ButtonPart.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		if Values.OwnerValue.Value == Player then
			if Debounce == false then
				Debounce = true
				
				if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, 20688106) then
					Player:WaitForChild("leaderstats").Cash.Value += Values.CashValue.Value * 1.5
					if Player.MembershipType == Enum.MembershipType.Premium then
						Player:WaitForChild("leaderstats").Cash.Value += Values.CashValue.Value * 0.2
					end
					wait()
					Values.CashValue.Value = 0
					wait(1)
					Debounce = false
				else
					Player:WaitForChild("leaderstats").Cash.Value += Values.CashValue.Value
					if Player.MembershipType == Enum.MembershipType.Premium then
						Player:WaitForChild("leaderstats").Cash.Value += Values.CashValue.Value * 0.2
					end
					wait()
					Values.CashValue.Value = 0
					wait(1)
					Debounce = false
				end
			end
		end
	end
end)

Instead of using NumberValues, you can use IntValues.
(Also, parent the Values on a separate line of code, I have done that below)

local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Value = 0
Cash.Parent = leaderstats
	
local Kills = Instance.new("IntValue")
Kills.Name = "Kills"
Kills.Value = 0
Kills.Parent = leaderstats

local Deaths = Instance.new("IntValue")
Deaths.Name = "Deaths"
Deaths.Value = 0
Deaths.Parent = leaderstats
1 Like

honestly it isn’t that new anymore

Well, that certainly wasn’t a solution I was expecting, lol. Thank you, though I suppose in the future I should look further into math floors & rounding in case code needs decimals or a higher number than the IntValue’s limit of 9.2 quintillion.

1 Like