I was scripting so much. Then I had to put all my scripts in a different game and finally found what the issue is.
CashLabel = script.Parent.Parent.Parent.Cash.CashValue
Leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats").Cash.Value
while true do
wait()
CashLabel.Text = "$ "..Leaderstats
end
This local script is the issue, any solutions why it won’t show the value on the cash gui text label?
You didn’t reference the value correctly and you should use events instead.
Try this:
--//Services
local Players = game:GetService("Players")
--//Variables
local LocalPlayer = Players.LocalPlayer
local Cash = LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Cash")
local CashLabel = script.Parent.Parent.Parent.Cash.CashValue
--//Functions
local function SetText()
CashLabel.Text = "$ ".. Cash.Value
end
SetText()
Cash.Changed:Connect(function()
SetText()
end)
local CashLabel = script.Parent.Parent.Parent.Cash.CashValue
local Leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats")
local function TextValue()
CashLabel.Text = "$ "..Leaderstats.Cash.Value
end
Leaderstats.Changed:Connect(function()
TextValue()
end)
local CashLabel = script.Parent.Parent.Parent.Cash.CashValue
local Leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Cash")
local function TextValue()
CashLabel.Text = "$ "..Leaderstats.Cash.Value
end
Leaderstats.Changed:Connect(function()
TextValue()
end)
Yes, but you don’t have to add another .Cash and you should run the function at the start. You should also use :GetService.
New code:
local Players = game:GetService("Players")
local CashLabel = script.Parent.Parent.Parent.Cash.CashValue
local Leaderstats = Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Cash")
local function SetText()
CashLabel.Text = "$ ".. Leaderstats.Value
end
SetText()
Leaderstats.Changed:Connect(function()
SetText()
end)
local Player = game:GetService("Players")
local CashLabel = script.Parent.Parent.Parent.Cash.CashValue
local Leaderstats = Player.LocalPlayer.WaitForChild("leaderstats"):WaitForChild("Cash")
local function TextValue()
CashLabel.Text = "$ "..Leaderstats.Value
end
TextValue()
Leaderstats.Changed:Connect(function()
TextValue()
end)
Ok it’s working. Question why can’t I just do game.Players.LocalPlayer and I have to do the player service??
local Player = game:GetService("Players")
local CashLabel = script.Parent.Parent.Parent.Cash.CashValue
local Leaderstats = Player.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Cash")
local function TextValue()
CashLabel.Text = "$ "..Leaderstats.Value
end
TextValue()
Leaderstats.Changed:Connect(function()
TextValue()
end)
It’s just because when you use game.Players, and an exploiter or someone names the Players service as for example apples, your script will error. If you use game:GetService though, this won’t happen because it doesn’t index directly through game, which is why it’s more efficient and safe.