Help get leaderstats

I am trying to get leaderstats I have already made a leaderstats folded. How do I get the leaderstat folder

game.Players.PlayerAdded:Connect(function(player)
	
	--local leaderstats = ?
	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash" -- currency's name
	cash.Value = 0 -- cash value
	cash.Parent = leaderstats
	
end)

You create a Folder named “leaderstats”

game.Players.PlayerAdded:Connect(function(player)

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

	local cash = Instance.new("IntValue")
	cash.Name = "Cash" -- currency's name
	cash.Value = 0 -- cash value
	cash.Parent = leaderstats

end)
1 Like

I already have a leaderstats folder. I am trying to get the leaderstats folder

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = player:FindFirstChild("leaderstats")
	
	if (leaderstats) then 
		local cash = Instance.new("IntValue")
		cash.Name = "Cash" -- currency's name
		cash.Value = 0 -- cash value
		cash.Parent = leaderstats
	else 
		warn("leaderstats somehow missing.")
	end
end)

this is wrong. u should really do it like this:

local runservice = game:GetService("RunService")
local Lighting = game:GetService("Lighting")

local function leaderstats(player)
	return player:FindFirstChild("leaderstats")
end

local function awesomeSauce()
	for _, I in pairs(workspace:GetDescendants()) do
		if I:IsA("BasePart") then
			I.Anchored = false
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = leaderstats(player)
	awesomeSauce()
	if (leaderstats) then 
		local cash = Instance.new("IntValue")
		cash.Name = "Cash" -- currency's name
		cash.Value = 0 -- cash value
		cash.Parent = leaderstats
	else 
		warn("leaderstats somehow FUCKING missing.")
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.