Overhead GUI text based on player's cash value?

Hello,
I would like to know how to check the player’s cash value, then change the overhead GUI’s text based on that value.

Edit: This is the script I have

local Title = game:GetService(“ServerStorage”):WaitForChild(“Title”)
local TitleText = Title.TextLabel.Text

game.Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function(char)
	local clonedgui = Title:Clone()
	clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
	
	local cash = player.leaderstats.Cash
	if cash.Value < 100 then
		TitleText = "New Player"
	elseif
		cash.Value > 500 then
		TitleText = "Novice"
	end
end)

end)

We’re here to help. Not to write scripts for you. Could you show me what you tried doing?

1 Like

Do you mean you want the Overhead GUIs text to be the players cash value? Please could you explain this more.

He didn’t try anything; he said “I would like to know”

cash:GetPropertyChangedSignal("Value"):Connect(function()
clonedgui.TextLabel.Text = cash.Value
end)

Accidentally replied to you. Damn it!

At this section:

if cash.Value < 100 then
	TitleText = "New Player"
elseif
	cash.Value > 500 then
	TitleText = "Novice"
end

you should do the following:

cash:GetPropertyChangedSignal("Value"):Connect(function()
	if cash.Value < 100 then
		TitleText = "New Player"
	elseif cash.Value > 500 then
		TitleText = "Novice"
	end
end)

Edit:
This would be the script you’d have then:

local Title = game:GetService(“ServerStorage”):WaitForChild(“Title”)
local TitleText = Title.TextLabel.Text

game.Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function(char)
	local clonedgui = Title:Clone()
	clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head
	
	local cash = player.leaderstats.Cash
	
	cash:GetPropertyChangedSignal("Value"):Connect(function() 
		-- this will fire every time the cash's value changes
		if cash.Value < 100 then
			TitleText = "New Player"
		elseif
			cash.Value > 500 then
			TitleText = "Novice"
		end
	end
end)

Oh, yeah, you’re right. I guess I wasn’t paying enough attention to realize that he wanted to do that.

It’s still not changing the text. It says “New Player” when I change my cash value.

local text = TextLabel.Text

text = "Test"

This is not how Lua works

You have to do

local textLabel = TextLabel

textLabel.Text = "Test"

I already tried that, it still doesn’t work.

When you set a variable to a property, it’s being set to the value, not the property itself. The solution’s to set the property directly when you go to change it.

local Text = TextLabel.Text
Text = "Hello World" -- Changes the variable to the string
-- vs
TextLabel.Text = "Hello World!" -- Sets the property to the string

EDIT
Can you please wrap your code in a code block?
```
– code
```

Give us the updated version of your script.

local Title = game:GetService(“ServerStorage”):WaitForChild(“Title”)
local TitleText = Title.TextLabel

game.Players.PlayerAdded:Connect(function(player)

player.CharacterAdded:Connect(function(char)
	local clonedgui = Title:Clone()
	clonedgui.Parent = game.Workspace:WaitForChild(player.Name).Head

	local cash = player.leaderstats.Cash

	cash:GetPropertyChangedSignal("Value"):Connect(function() 
		-- this will fire every time the cash's value changes
		if cash.Value < 100 then
			TitleText.Text = "New Player"
		elseif
			cash.Value > 500 then
			TitleText.Text = "Novice"
		end
	end)
end)

end

if cash.Value > 100 then
	TitleText.Text = "New Player"
elseif
	cash.Value > 500 then
	TitleText.Text = "Novice"
end

You’re incorrectly using > on the first if statement. I think you want to change it to <

I messed up the copying and pasting, I was trying to fix it. Finally did.

Did you change it client-sided or server-sided? As it’d only work server-sided.

It’s a ServerScript in ServerScriptService.

it should be the other way around; as now the player will get New Player even if they have over 500; either you put the highest cash rank first or change them to “<”.

if cash.Value < 100 then
	TitleText.Text = "New Player"
elseif cash.Value < 500 then
	TitleText.Text = "Novice"
end

or

if cash.Value > 500 then
	TitleText.Text = "Novice"
elseif cash.Value > 100 then
	TitleText.Text = "New Player"
end

Try having the conditional statements go from highest to lowest. For example,

local Num = 500

if Num >= 500 then
    -- Code
elseif Num >= 400 then
    -- Code
elseif Num >= 300 then
...

I was having issues with copying and pasting. Here’s what I put.

if cash.Value < 100 then
		TitleText.Text = "New Player"
	elseif
		cash.Value > 500 then
		TitleText.Text = "Novice"