Not a valid member of Player

Hey Developers,

I keep receiving this error which is “not valid member of Player” when the folder is defiantly inside the player and my script is using :WaitForChild() but it’s still saying it’s not a part of the player.

Code:

local Player = game.Players.LocalPlayer
local Exp = Player:WaitForChild("XPstuff").Exp

image

Any help would be appreciated as I’ve never experienced this error before.

Is it because Local Player isn’t in the Players Service, it’s in the workspace?

This is a weird bug, are you sure it’s the code you’re using causing the error?

1 Like

I don’t believe so, this is how I’m creating the folder when the player joins:

local leaderstats = Instance.new("Folder")
	leaderstats.Name = "XPstuff"
	leaderstats.Parent = Player

LocalPlayer is not an instance, but can be used in a local script to get the clients player instance.

2 Likes

Extremely weird bug, have you checked if you’re running a previous version of the script that directly referenced the instance? You may need to commit your script

(WaitForChild() erroring on referencing a child to a existing instance is impossible, its supposed to warn you of an infinite yield)

I’ve never seen this bug happen before, try this:

local function GetInstance(player : Instance, instance : string)
   for _, v in next, player:GetChildren() do
      if v.Name == instance then
         return v
      end
   end
end

task.wait()
local Player = game.Players.LocalPlayer
local XPstuff = GetInstance(Player, "XPstuff")
local Exp = XPstuff.Exp

Is their player joined function? Play the game and look in your player to see if the folder is there.

Try this
local Player = game:GetService("Players").LocalPlayer
local Exp = Player:WaitForChild("XPstuff").Exp

if Exp then
   print("Exp!")
else
   print("Error!")
end
2 Likes

Try changing your code so you have 2 wait for childs. When creating values with Instance.new(), it may be delayed. Like this:

local Player = game.Players.LocalPlayer
local Exp = Player:WaitForChild("XPstuff"):WaitForChild("Exp")

I have that error at some moments so i do something like that.

local Player = game.Players.LocalPlayer
local XPstuff = Player:WaitForChild("XPstuff")
local Exp = XPstuff:WaitForChild("Exp")

Nope, that didn’t fix it.
image

image

local Player = game:GetService("Players").LocalPlayer
local Folder = Player:WaitForChild('XPstuff')

Is literally all you need.

This shouldn’t happen when using :WaitForChild(). If you are using WaitForChild and the child you are trying to wait for doesn’t exist yet, then the output should say infinite yield possible on some object.

Yes, and check if something is not deleting the file after it being found

Can you send the full script(s)? I don’t believe the error is being returned by the script you’re actually editing, as aforementioned, it should be returned as infinite yield if it doesn’t exist.

After you changed your script to the suggested edits, the error was still there, making me believe you have more than one script attempting to reference the folder.

Server Script

--variables
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ValueDB = DataStoreService:GetDataStore("Charred_Datastore")

--functions
local function saveData(Player)
	local Values = {
		Player.XPstuff.Level.Value;
		Player.XPstuff.Exp.Value;
	}
	pcall(function()
		ValueDB:SetAsync(Player.UserId, Values)
	end)
end




local function PlayerAdded(Player)
	wait(2)
	--setup
	local data
	
	local s, e = pcall(function()
		data = ValueDB:GetAsync(Player.UserId)
	end)
	
	if not s then warn(e) end
	
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "XPstuff"
	leaderstats.Parent = Player
	
	local Level = Instance.new("NumberValue",leaderstats)
	Level.Name = "Level"
	
	local Exp = Instance.new("NumberValue",leaderstats)
	Exp.Name = "Exp"
	
	local RequiredExp = Instance.new("NumberValue", Player)
	RequiredExp.Name = "RequiredExp"
	RequiredExp.Value  = Level.Value * 100
	
	if data and data[1] then
		Level.Value = data[1]
	else
		Level.Value = 1
	end
	
	if data and data[2] then
		Exp.Value = data[2]
	else
		Exp.Value = 0
	end
	
	
	--maincode
	Exp.Changed:Connect(function(Changed)
		if Exp.Value>= RequiredExp.Value then
			Exp.Value = 0
			Level.Value += 1
			RequiredExp.Value = Level.Value * 100
			
			
			
		end
	end)
end



local function PlayerRemoving(Player)
	saveData(Player)
end

for _, Player in ipairs(Players:GetPlayers()) do
	PlayerAdded(Player)
end

Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)

Local Script

task.wait()
local Player = game.Players.LocalPlayer
local Xpstuff = Player:WaitForChild('XPstuff')
local Exp = Xpstuff.Exp
local RequiredExp = Player.RequiredExp

Exp.Changed:Connect(function(Changed)
if Changed then
script.Parent.XPBar.Bar:TweenSize(UDim2.new(Exp.Value/ RequiredExp.Value,0,1,0))
end
end)
while task.wait() do
script.Parent.Percent.Text = Exp.Value.."/"..RequiredExp.Value
end

perhaps do

repeat
task.wait()
until game.Players.LocalPlayer:FindFirstChild("XPstuff")
local Folder = game.Players.LocalPlayer:FindFirstChild("XPstuff")

or do

game.Players.LocalPlayer.ChildAdded:Connect(function(child)
if child.Name == "XPstuff" then
-- Your script
end end)

the above but without delaying anything

game.Players.LocalPlayer.ChildAdded:Connect(function(child)
if child.Name == "XPstuff" then
spawn(function()
-- Your script
end) end end)

if none of the above work then really its a problem with the name
make sure to check that there are no spaces or diffrent characters (rewrite the name)


Edit : I found the reason it doesnt work because

this has a 2 second delay (the server script)
and the local script

has only 0.01 seconds (somewhere there)
you dont need a delay on the server script unless that really is until player is fully loaded but im sure there is no use since nothing is covering with character so…
yeah.

That shouldn’t happen. When the game errors with :WaitForChild() It will say something about infinite wait. This probably means you have either the wrong script, or you didn’t commit the script.

its infinite yield but i found out that this is a delay issue check the scripts he posted.