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

Leaderboard showing 1000 when it should show 1k?

I want my leaderboard to show 1k instead of 1000 and also do that with higher numbers but it is not working correctly.

I am also getting an error saying: ServerScriptService.leaderboard:9: attempt to compare number with string 20:31:42.420 - Stack Begin

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	local cash = Instance.new("StringValue",leaderstats)
	cash.Name = "Cash"
	cash.Value = 0
	
	while wait() do
		if cash.Value >= 1000 then
			cash.Value = string.sub(tostring(cash.Value),1,1).."K"
		end
	end
end)

3 comments

0

Your comparing a string value when you did local cash = Instance.new() try turning the value of cash to a number

0

Why not use IntValue instead?

0

He can't use letters with a value that expects an integer.

1 answer

✓ Accepted answer

The problem is your cash object is a StringValue, and you are checking if the string is >= 1000. You can't check if a string is larger than a number, that's like saying:

is 'd' greater than 6?

So you instead have to convert the string to a number, and then perform the comparison:

if tonumber(cash.Value) >= 1000 then
	cash.Value = string.sub(cash.Value), 1, 1) .. "K"
end

Also you said cash.Value = 0, you should change that to cash.Value = "0".

Hope this helps :)

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