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.
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)
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
local Player = game:GetService("Players").LocalPlayer
local Exp = Player:WaitForChild("XPstuff").Exp
if Exp then
print("Exp!")
else
print("Error!")
end
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.
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.
--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
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.