Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My script can't find the leaderstats, any ideas?

Asked by 4 years ago

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?

0
That's because you cannot use a local player when trying to change things such as leaderstats e.t.c JesseSong 3916 — 4y
0
Also what are you trying to do on line 4 JesseSong 3916 — 4y
0
changing the name of the folder Diamond52002 29 — 4y
0
If you are trying to change anything then you need to use remote events instead of local unless you have filteringenabled turned off Barty200 85 — 4y

Answer this question