I have a text on screen that shows their cash abbreviate, but if they hover over it, they can see the full amount if the player wants to see it specifically. I used if statement at the bottom of script, but it seems to not work. Not really sure as I first joined, number is 0, however hover over the text, shows the full number. Any idea?

	N = 10^30;
	O = 10^27;
	Sp = 10^24;
	Sx = 10^21;
	Qn = 10^18;
	Qd = 10^15;
	T = 10^12;
	B = 10^9;
	M = 10^6;
	K = 10^3
}


function abbreviateNums(number)


	local abbreviatedNum = number
	local abbreviationChosen = 0


	for abbreviation, num in pairs(abbreviations) do

		if number >= num and num > abbreviationChosen then

			local shortNum = number / num
			local intNum = math.floor(shortNum)

			abbreviatedNum = tostring(intNum) .. abbreviation .. "+"
			abbreviationChosen = num
		end
	end

	return abbreviatedNum
end

while wait(1) do
	script.Parent.MouseEnter:Connect(function()
		
		if script.Parent.MouseEnter == false then
			
			local player = game.Players.LocalPlayer
			
			script.Parent.Text = abbreviateNums(player.stats.Cash.Value)
		else
			script.Parent.Text = game.Players.LocalPlayer.stats.Cash.Value
			end
		end)
end

Edit: This works kinda but hover over for a second and it changes the text. The while wait(1) overwrites mouseenter text, I think. Thought if mouse is entered true then returns, but doesn't.

script.Parent.MouseEnter:Connect(function()

	local player = game.Players.LocalPlayer
	script.Parent.Text = abbreviateNums(player.stats.Cash.Value)
end)

if script.Parent.MouseEnter == true then
	return
		else
		while wait(1) do

		local player = game.Players.LocalPlayer
		script.Parent.Text = player.stats.Cash.Value
	end
end

5 comments

0

line 36 You don't need a while loop. Do you know how events work?

0

No lol. Just doing the trial and error strat

0

Remove the while loop and do this player.stats.Cash:GetPropertyChangedSignal("Value"):Connect(function(); script.Parent.Text = player.stats.Cash.Value;

0

You should avoid using wait it can make your game lag. https://devforum.roblox.com/t/avoiding-wait-and-why/244015

0

Thank you! Big ups