So I set up cash leaderstats in my game, the leaderstats work perfectly fine but whenever I try to reference leaderstats in a script it errors out saying "attempt to index nil with 'leaderstats'"
Script used to setup leaderstats:
local function onPlayerJoin(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local cash = Instance.new("IntValue") cash.Name = "Cash" cash.Value = 10 cash.Parent = leaderstats end -- this script works as intended game.Players.PlayerAdded:Connect(onPlayerJoin)
this is the script that is showing the error:
local Players = game:GetService("Players") local player = Players.LocalPlayer local cash = player.leaderstats.Cash.Value
any ideas?