Hmmm. So like when I made leaderstats I should do like. Including all my scripts that I make that involve player?
local Player = game:getservice(“player”)
leaderstats.Parent = Player
Hmmm. So like when I made leaderstats I should do like. Including all my scripts that I make that involve player?
local Player = game:getservice(“player”)
leaderstats.Parent = Player
Yes.
Ok I’ll change it for ALL my scripts. Thank you so much. Fr I learned a lot today
No problem. If you have any more questions, feel free to ask. (also make sure to set one of the posts as the solution so people don’t waste their time replying)
Ok. I jsut realized. I should do it for other things like lighting service and other.
Check the snippet of code posted below.
You forgot to add the value parameter:
local Players = game:GetService("Players")
local CashLabel = script.Parent.Parent.Parent.Cash.CashValue
local Leaderstats = Players.LocalPlayer:WaitForChild("leaderstats")
local Cash = Leaderstats:WaitForChild("Cash")
local function SetText(CashValue)
CashLabel.Text = "$ ".. CashValue
end
Cash.Changed:Connect(SetText)
SetText(Cash.Value) --Connection first then call function.
Seems my previous edit didn’t go through, here it is.
local ScreenGui = script:FindFirstAncestorOfClass("ScreenGui") --More readable than 'script.Parent.Parent.Parent...'.
local CashFrame = ScreenGui:WaitForChild("Cash") --Should wait for this to replicate.
local CashLabel = CashFrame:WaitForChild("CashValue") --Should also wait for this to replicate.
local Players = game:GetService("Players")
local Player = Players.LocalPlayer --May as well declare a reference for the local player.
local Leaderstats = Player:WaitForChild("leaderstats")
local Cash = Leaderstats:WaitForChild("Cash")
local function SetText(CashValue)
CashLabel.Text = string.format("$%.2f", CashValue) --Properly format the value.
end
Cash.Changed:Connect(SetText)
task.spawn(SetText, Cash.Value) --Run this in its own thread (as 'Changed' would do).