Help With Gui Text

Hey, I’m WiseMatheu and I’m currently making a tycoon. Everything is working well but I’m wondering how you can make the text on a cash collector show 2.5k instead of 2500.

image

If you have an idea please post it below.

Have a nice day,
WiseMatheu :slightly_smiling_face:

1 Like

Try using Google to search before.

Code from ScriptingHelpers:

local Notation = {"K", "M", "B", "T", "Q", "Qu", "S", "Se", "O", "Number", "D"}

local function ConvertNumber(Number)
    for i = #Notation, 1, -1 do
        local v = math.pow(10, i * 3)
        if Number >= v then
            return ("%.0f"):format(Number / v) .. Notation[i]
        end
    end
    return tostring(Number)
end

Call the function like this local NewNumberString = ConvertNumber(1212121)

I’m not really a scripter so where shall I put this script and when do I call it?

You need to look for the script that updates the UI with the money text. You can provide the code here, after you do so

Do I put it anywhere in the script?

Assuming you don’t have any knowledge doing this, you can provide the code here and I’ll edit it for you.

--- Variables ---

local TycoonModel = script.Parent.Parent
local Items = {}

local BoughtItems = TycoonModel:FindFirstChild("BoughtItems")
local Buttons = TycoonModel:FindFirstChild("Buttons")
local DropperParts = TycoonModel:FindFirstChild("DropperParts")
local MainItems = TycoonModel:FindFirstChild("MainItems")
local Scripts = TycoonModel:FindFirstChild("Scripts")
local Values = TycoonModel:FindFirstChild("Values")

--- Owner Functions ---

MainItems.OwnerDoor.MainDoor.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") and Values.OwnerValue.Value == nil then
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		Values.OwnerValue.Value = Player
		MainItems.OwnerDoor.MainDoor.SurfaceGui.TextLabel.Text = tostring(Values.OwnerValue.Value).."'s Tycoon"
	end
end)


--- Cash Functions ---

local Debounce = false

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
				Player:WaitForChild("Leaderstats").Cash.Value += Values.CashValue.Value
				wait()
				Values.CashValue.Value = 0
				wait(1.5)
				Debounce = false
			end
		end
	end
end)

while wait() do
	MainItems.CashButton.ScreenPart.SurfaceGui.TextLabel.Text = Values.CashValue.Value
end

This should fix it then.

local TycoonModel = script.Parent.Parent
local Items = {}

local BoughtItems = TycoonModel:FindFirstChild("BoughtItems")
local Buttons = TycoonModel:FindFirstChild("Buttons")
local DropperParts = TycoonModel:FindFirstChild("DropperParts")
local MainItems = TycoonModel:FindFirstChild("MainItems")
local Scripts = TycoonModel:FindFirstChild("Scripts")
local Values = TycoonModel:FindFirstChild("Values")

--- Owner Functions ---

MainItems.OwnerDoor.MainDoor.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") and Values.OwnerValue.Value == nil then
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		Values.OwnerValue.Value = Player
		MainItems.OwnerDoor.MainDoor.SurfaceGui.TextLabel.Text = tostring(Values.OwnerValue.Value).."'s Tycoon"
	end
end)


--- Cash Functions ---

local Debounce = false

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
				Player:WaitForChild("Leaderstats").Cash.Value += Values.CashValue.Value
				wait()
				Values.CashValue.Value = 0
				wait(1.5)
				Debounce = false
			end
		end
	end
end)

local Notation = {"K", "M", "B", "T", "Q", "Qu", "S", "Se", "O"}

local function ConvertNumber(Number)
	if typeof(Number) == 'string' then Number = tonumber(Number) end;
	for i = #Notation, 1, -1 do
		local v = math.pow(10, i * 3)
		if Number >= v then
			return ("%.0f"):format(Number / v) .. Notation[i]
		end
	end
	return tostring(Number)
end

Values.CashValue:GetPropertyChanged'Value':Connect(function()
	MainItems.CashButton.ScreenPart.SurfaceGui.TextLabel.Text = ConvertNumber(Values.CashValue.Value);
end);

There’s an error and the UI doesn’t say anything now:
image

My bad, I misspelled it.

local TycoonModel = script.Parent.Parent
local Items = {}

local BoughtItems = TycoonModel:FindFirstChild("BoughtItems")
local Buttons = TycoonModel:FindFirstChild("Buttons")
local DropperParts = TycoonModel:FindFirstChild("DropperParts")
local MainItems = TycoonModel:FindFirstChild("MainItems")
local Scripts = TycoonModel:FindFirstChild("Scripts")
local Values = TycoonModel:FindFirstChild("Values")

--- Owner Functions ---

MainItems.OwnerDoor.MainDoor.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") and Values.OwnerValue.Value == nil then
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		Values.OwnerValue.Value = Player
		MainItems.OwnerDoor.MainDoor.SurfaceGui.TextLabel.Text = tostring(Values.OwnerValue.Value).."'s Tycoon"
	end
end)


--- Cash Functions ---

local Debounce = false

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
				Player:WaitForChild("Leaderstats").Cash.Value += Values.CashValue.Value
				wait()
				Values.CashValue.Value = 0
				wait(1.5)
				Debounce = false
			end
		end
	end
end)

local Notation = {"K", "M", "B", "T", "Q", "Qu", "S", "Se", "O"}

local function ConvertNumber(Number)
	if typeof(Number) == 'string' then Number = tonumber(Number) end;
	for i = #Notation, 1, -1 do
		local v = math.pow(10, i * 3)
		if Number >= v then
			return ("%.0f"):format(Number / v) .. Notation[i]
		end
	end
	return tostring(Number)
end

Values.CashValue.Changed:Connect(function()
	MainItems.CashButton.ScreenPart.SurfaceGui.TextLabel.Text = ConvertNumber(Values.CashValue.Value);
end);

This is incorrect the correct code:

Values.CashValue:GetPropertyChanged('Value'):Connect(function()

1 Like

That’s incorrect. It’s :GetPropertyChangedSignal'Value' but it’s not needed here, that’s why I used .Changed instead.

Thank you @WhitexHat and @apoaddda, I’ve marked the message as the solution. :slightly_smiling_face: