Leaderstats is not a valid member of Player

Hello, I tried to make currency for joining group. For some reason, it always shows an error (leaderstats is not a valid member of Player “Players.CrystalGames_Holder”). Does anyone know what’s wrong?

 game.Players.PlayerAdded:Connect(function(player)
	if player:IsInGroup(4352965)then
		player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 10000
	end
end)

klomc
image

Wiat for it to exist using WaitForChild

game.Players.PlayerAdded:Connect(function(player)
	if player:IsInGroup(4352965)then
		local stats = player:WaitForChild("leaderstats")
		local gems = stats:WaitForChild("Gems")
		gems.Value += 10000
	end
end)

@ThunderFrost0001 Thank you for that, I’ve included it as well

4 Likes

I’d also suggest to use WaitForChild on Gem value as well in-case it doesn’t appear instantly.

1 Like