Attempt to index Nil with WaitForChild

I have been trying to create stats for the player, for some reason one decides to work and the other doesn’t? I’m just trying to get some help.

Their BOTH NumberValues and I really don’t see why this is happening??

local playerStats = GameData:AddPlayerStatistics(Player)
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 47763491) then
		-- Gives more energy
		playerStats.Energy.Max.Cap.Value = 150 -- WORKS
		playerStats.Energy.Max.Value = 150 -- THESE WORK
    end
	for i, v in pairs(M.StarterTools[Player:GetRankInGroup(M.GroupId)]) do
		if Storage.Tools:FindFirstChild(v) then
			Storage.Tools[v]:Clone().Parent = Player.StarterGear
			Storage.Tools[v]:Clone().Parent = Player.Backpack
		end
	end

	playerStats:WaitForChild("Rank").Value = Player:GetRankInGroup(M.GroupId)  -- Where the error is at.

Thank you!!!

playerStats seems like a table. Try making playerStats an actual instance. Just do

repeat
wait()
playerStats = GameData:AddPlayerStatistics(Player)
until playerStats
playerStats.Rank.Value = Player:GetRankInGroup(M.GroupId)

Yesss Thank you so much it worked.

1 Like