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)
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)
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
```
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)
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