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

How do I abreviate leaderstats?

This script works for the cur1, but it doesn't work for the other currencies.

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder")
	folder.Name = "XD"
	folder.Parent = player
	
	local cur1 = Instance.new("IntValue")
	cur1.Name = "Coins"
	cur1.Value = 5000
	cur1.Parent = folder
	
	local cur2 = Instance.new("IntValue")
	cur2.Name = "Gems"
	cur2.Value = 5000
	cur2.Parent = folder
	
	local cur3 = Instance.new("IntValue")
	cur3.Name = "things"
	cur3.Value = 5000
	cur3.Parent = folder
	
	local cur4 = Instance.new("IntValue")
	cur4.Name = "Total"
	cur4.Value = 5000
	cur4.Parent = folder
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local fake1 = Instance.new("StringValue")
	fake1.Name = cur1.Name
	fake1.Value = tostring(cur1.Value)
	fake1.Parent = leaderstats
	
	local fake2 = Instance.new("StringValue")
	fake2.Name = cur2.Name
	fake2.Value = tostring(cur2.Value)
	fake2.Parent = leaderstats
	
	local fake3 = Instance.new("StringValue")
	fake3.Name = cur3.Name
	fake3.Value = tostring(cur3.Value)
	fake3.Parent = leaderstats

	local fake4 = Instance.new("StringValue")
	fake4.Name = cur4.Name
	fake4.Value = tostring(cur4.Value)
	fake4.Parent = leaderstats





	while wait() do
		local x = tostring(cur1.Value)
		if #x >= 10 then
			fake1.Value = x:sub(0,(#x-9)).."."..(x:sub(#x-7,(#x-7))).."B+"
	
		elseif #x >= 7 then
			fake1.Value = x:sub(0,(#x-6)).."."..(x:sub(#x-5,(#x-5))).."M+"
		
		elseif #x >= 4 then
			fake1.Value = x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
		else
			fake1.Value = tostring(cur1.Value)
			
	
	while wait() do
		local x = tostring(cur2.Value)
		if #x >= 10 then
			fake2.Value = x:sub(0,(#x-9)).."."..(x:sub(#x-7,(#x-7))).."B+"
	
		elseif #x >= 7 then
			fake2.Value = x:sub(0,(#x-6)).."."..(x:sub(#x-5,(#x-5))).."M+"
		
		elseif #x >= 4 then
			fake2.Value = x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
		else
			fake2.Value = tostring(cur2.Value)
			
			
	while wait() do
		local x = tostring(cur3.Value)
		if #x >= 10 then
			fake3.Value = x:sub(0,(#x-9)).."."..(x:sub(#x-7,(#x-7))).."B+"
	
		elseif #x >= 7 then
			fake3.Value = x:sub(0,(#x-6)).."."..(x:sub(#x-5,(#x-5))).."M+"
		
		elseif #x >= 4 then
			fake3.Value = x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
		else
			fake3.Value = tostring(cur3.Value)
			
			
	while wait() do
		local x = tostring(cur4.Value)
		if #x >= 10 then
			fake4.Value = x:sub(0,(#x-9)).."."..(x:sub(#x-7,(#x-7))).."B+"
	
		elseif #x >= 7 then
			fake4.Value = x:sub(0,(#x-6)).."."..(x:sub(#x-5,(#x-5))).."M+"
		
		elseif #x >= 4 then
			fake4.Value = x:sub(0,(#x-3)).."."..(x:sub(#x-2,(#x-2))).."K+"
		else
			fake4.Value = tostring(cur4.Value)
	
	end
	end
		end
	end
		end
		end
		end
	end
		end)

6 comments

0

Can you explain your question better? I'm not going to look through 117 lines of code for errors, when I don't even know exactly what the problem is.

0

oh, this displays 5.1k instead of 5100 and the coins is working but the gems arent.

0

your while loops are so messy

0

sorry i didn't finish my code but i've editted it. you can read it now

0

1/3 of the questions on this website are literally this same question

0

This code made me throw up in my mouth.

1 answer

✓ Accepted answer

hello, idk really because you've got some messy stuff there so i'll just suggest you what i'd do to fix this.

cur1.Changed:Connect(function(aValue)
	local bValue = tostring(aValue); -- x
	local bLength = string.len(bValue);
	if(bLength >= 10) then
		local bSub = string.sub(bValue,0,bLength - 9);
		local dSub = string.sub(bValue,bLength - 7,bLength - 7);
		fake1.Value = bSub.."."..dSub.."B+";
	elseif(bLength >= 7) then
		local bSub = string.sub(bValue,0,bLength - 6);
		local dSub = string.sub(bValue,bLength - 5,bLength - 5);
		fake1.Value = bSub.."."..dSub.."M+";
	elseif(bLength >= 4) then
		local bSub = string.sub(bValue,0,bLength - 3);
		local dSub = string.sub(bValue,bLength - 2,bLength - 2);
		fake1.Value = bSub.."."..dSub.."K+";
	else
		fake1.Value = bValue;
	end
end)
--// same thing for other currencies

hope it helped.

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