I am trying to make it so a gui text shows you a leaderstat value because it won’t show normally on mobile, so I created a script that does that but got error 13:02:06.242 - leaderstats is not a valid member of Player
Script for gui text:
local cash = game.Players.player.leaderstats:WaitForChild("Gold")
function changed()
script.Parent.Text = "Gold: $"..cash.Value
end
cash.Changed:connect(changed)
Script for leaderstat (datastore):
local datastore = game:GetService("DataStoreService"):GetDataStore("GameStore")
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Money = Instance.new("IntValue")
Money.Name = "Gold"
Money.Parent = leaderstats
local key = "user-" .. player.userId
local storeditems = datastore:GetAsync(key)
if storeditems then
Money.Value = storeditems[1]
end
end)
game.Players.PlayerRemoving:connect(function(player)
local items = {player.leaderstats.Gold.Value}
local key = "user-" .. player.userId
datastore:SetAsync(key, items)
end)