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

Attempt to index nil with leaderstats? (HELP)

Asked by 3 years ago

So my code for a keycard wont work can anyone help?

local rs = game:WaitForChild("ReplicatedStorage")
local fa = rs.AccessCards.FullAccess
local leaderstats = game.Players.LocalPlayer.leaderstats --could be the problem
game.Players.PlayerAdded:Connect(function(player)
    if leaderstats.Rank.Value == ("Dev.. Mayor Chill") then -- could also be the problem
        local clone = fa:Clone()
        clone.Parent = player.Backpack
    end
end)

2 answers

Log in to vote
0
Answered by 3 years ago

I think I got it. LocalPlayer doesn't load in for a long time, instead use player.leaderstats where checking for a rank. Hopefully it works, otherwise add in a 0.2 second delay to let it all load in!

0
Didnt work Lamborghinihurican0 4 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

ive got a new code but now its indexing nil with Backpack

local rs = game:WaitForChild("ReplicatedStorage")
local fa = rs.AccessCards.FullAccess
game.Players.PlayerAdded:Connect(function(player)
    wait(0.2)
    local leaderstats = player:WaitForChild("leaderstats")
    local players = game.Players.LocalPlayer
    local backpack = players.BackPack
    if leaderstats.Rank.Value == ("Dev") then
        local clone = fa:Clone()
        clone.Parent = backpack
    end
end)

0
It is spelled "Backpack" FrontsoldierYT 129 — 3y
0
Are you trying to clone this for everybody's backpacks in the game? RazzyPlayz 497 — 3y
0
no Lamborghinihurican0 4 — 3y
0
Is it local script or server script jerryisgod29 176 — 3y
0
server Lamborghinihurican0 4 — 3y

Answer this question