Cannot find Leaderstat

I have a script that prints a leaderstat value, when I do it, it gives me and error message of “attempted nil value with: WaitForChild”

script.Parent.MouseButton1Click:Connect(function(player)
   local stats = player:WaitForChild("Stats")
   print(stats.Exp)
end)

I can see the Stats Folder and the Exp value in the player. So I don’t understand this error

image

MouseButton1Click does not return the player, it does not give something back, if it is a localscript use LocalPlayer

Like @SOTR654 said MouseButton1Click doesn’t give anything so instead use this script

local player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
   local stats = player:WaitForChild("Stats")
   print(stats.Exp)
end)

It does not return a player, and second is you cannot print an instance say instance.Value for values

Use this script:

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
   if player then
     local stats = player.Stats
     print(stats.Exp.Value)
  end
end)

Make sure that’s LocalScript.
Use instead print(stats.exp.Value)
Because MouseButton1Click doesn’t return the player.
Delete the player from function.
Use instead local player = game.Players.LocalPlayer

1 Like