Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to index nil with leaderstats? (HELP)

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

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!

1 comment

0

Didnt work

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)

5 comments

0

It is spelled "Backpack"

0

Are you trying to clone this for everybody's backpacks in the game?

0

no

0

Is it local script or server script

0

server

This discussion is preserved as it was. New answers, comments, and votes are closed.