Leaderstat error

I get an error saying that wool is not part of leaderstats, but it actually is.

Here is my script causing the error.

local u1 = {"", 'K', "M", "B", "T", "Qa", "Qi", "Sx", "Sp", "Oc", "No", "Dc"}
function v1(p1)
	for v2 = 1, #u1 do
		if tonumber(p1) < 10 ^ (v2*3) then
			return math.floor(p1/(10^((v2-1)*3)/100))/100 .. u1[v2]
		end
	end
end

local player = game.Players.LocalPlayer
while wait() do
	script.Parent.TextLabel.Text  = v1(player:WaitForChild("leaderstats").Wool.Value)
end

My leaderstats:

local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("MyDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	coins = Instance.new("NumberValue")
	coins.Name = "Gold"
	coins.Parent = leaderstats
	if myDataStore:GetAsync(player.UserId..' - Gold') then
		coins.Value =  myDataStore:GetAsync(player.UserId..' - Gold')
	else
		coins.Value = 0
	end

	Eggs = Instance.new("NumberValue")
	Eggs.Name = "Eggs"
	Eggs.Parent = leaderstats    
	if myDataStore:GetAsync(player.UserId..' - Eggs') then
		Eggs.Value =  myDataStore:GetAsync(player.UserId..' - Eggs')
	else
		Eggs.Value = 0
	end

	Milks = Instance.new("NumberValue")
	Milks.Name = "Milk"
	Milks.Parent = leaderstats    
	if myDataStore:GetAsync(player.UserId..' - Milks') then
		Milks.Value =  myDataStore:GetAsync(player.UserId..' - Milks')
	else
		Milks.Value = 0
	end
	
	Wool = Instance.new("NumberValue")
	Wool.Name = "Wool"
	Wool.Parent = leaderstats    
	if myDataStore:GetAsync(player.UserId..' - Wool') then
		Wool.Value =  myDataStore:GetAsync(player.UserId..' - Wool')
	else
		Wool.Value = 0
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local s,e = pcall(function()
		myDataStore:SetAsync(player.UserId..' - Gold',coins.Value)
	end)
	if e then
		warn('Failed saving "Gold" for '..player.DisplayName)
	end

	local s,e = pcall(function()
		myDataStore:SetAsync(player.UserId..' - Eggs',Eggs.Value)
	end)
	if e then
		warn('Failed saving "Eggs" for '..player.DisplayName)
	end

	local s,e = pcall(function()
		myDataStore:SetAsync(player.UserId..' - Milks',Milks.Value)
	end)
	if e then
		warn('Failed saving "Milk" for '..player.DisplayName)
	end
	
	local s,e = pcall(function()
		myDataStore:SetAsync(player.UserId..' - Wool',Wool.Value)
	end)
	if e then
		warn('Failed saving "Wool" for '..player.DisplayName)
	end
end)

game:BindToClose(function()
	for i, player in pairs(game.Players:GetChildren()) do
		player:Kick("Server Closed")
	end

	wait(2)
end)

My leaderstat don’t always work in gui form.

Is the wool thing in the leaderstats file? Also can i see the entire error in the output?

You shouldn’t be using while wait() do for this.

Change your client code to this:

--//Services
local Players = game:GetService("Players")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Wool = LocalPlayer:WaitForChild("leaderstats"):WaitForChild("Wool")
local TextLabel = script.Parent.TextLabel

--//Tables
local u1 = {"", 'K', "M", "B", "T", "Qa", "Qi", "Sx", "Sp", "Oc", "No", "Dc"}

--//Functions
local function v1(p1)
	for v2 = 1, #u1 do
		if tonumber(p1) < 10 ^ (v2*3) then
			return math.floor(p1/(10^((v2-1)*3)/100))/100 .. u1[v2]
		end
	end
end

local function SetText(value)
	TextLabel.Text = v1(value)
end

Wool.Changed:Connect(function(value)
	SetText(value)
end)

SetText(Wool.Value)
3 Likes

To be honest I think it’s because the script is already running BRFORE your server script can add the ‘Wool’ thing into leaderstats which may be what’s causing it to not be a child. Also do what the user above me said

Ty so much!! I appreciate your help!

1 Like

No problem. If you have any more questions, feel free to ask.

1 Like