Leaderstat question

Hi! So I have made leaderstats for coins and wins through this script:

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


	local toolsOwned = {}
	local coins = 0
	local wins = 0
	local skips = 0
	pcall(function()
		toolsOwned = ds:GetAsync("tools-" .. plr.UserId) or {}
		coins = ds:GetAsync("coins-" .. plr.UserId) or 0
		wins = ds:GetAsync("wins-" .. plr.UserId) or 0
		skips = ds:GetAsync("wins-" .. plr.UserId) or 0
	end)
	
	


	local ls = Instance.new("Folder", plr)
	ls.Name = "leaderstats"

	local coinsValue = Instance.new("IntValue", ls)
	coinsValue.Name = "Coins"
	coinsValue.Value = coins

	local winsValue = Instance.new("IntValue", ls)
	winsValue.Name = "Wins"
	winsValue.Value = wins

	print(skips)

	
	local skipsValue = Instance.new("IntValue", ls)
	skipsValue.Name = "Skips"
	skipsValue.Value = skips




	local ownedFolder2 = Instance.new("Folder", plr)
	ownedFolder2.Name = "OwnedTools"



	for i, owned in pairs(toolsOwned) do

		if tools:FindFirstChild(owned) then

			tools[owned]:Clone().Parent = ownedFolder2
		end
	end









end)

Is there a way I can keep the skipsValue in that leaderstat folder but not have it displayed on the top right of the screen?
image

2 Likes

Unless you make it something other than a Value. Maybe inserting a text label and setting the text to “skips” would work.

Through a seperate script, I need skips to be accessed as a number. I also need it to be saved through datastore so I don’t know if a label would work.

Using tonumber(label.text) should convert a string to a number

Yes but would it be saved in datastore accurately?

As long as its saved as a number. You also don’t have to put it in leaderstats to save

Could I make a new folder with a skip intValue for each player that would be saved in datastore?

I’m not sure if this would work, but you could try to make a folder inside of the leaderstats, (I would call it “HiddenValues”) and put the Skips inside of there.

Would it be saved by datastore?

I recommend using attributes for that.

Do you mind expanding on that?

Attributes can be get and set by GetAttribute and SetAttribute, where you simply set the attribute’s value to a number and can later retrieve it with GetAttribute. You can create an attribute for the leaderstats folder and then you can set it to the value you want.

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

	local toolsOwned = {}
	local coins = 0
	local wins = 0
	local skips = 0
	pcall(function()
		toolsOwned = ds:GetAsync("tools-" .. plr.UserId) or {}
		coins = ds:GetAsync("coins-" .. plr.UserId) or 0
		wins = ds:GetAsync("wins-" .. plr.UserId) or 0
		skips = ds:GetAsync("skips-" .. plr.UserId) or 0 -- Get the skips
	end)
	
	


	local ls = Instance.new("Folder", plr)
	ls.Name = "leaderstats"

	local hs = Instance.new("Folder", plr) -- Stats folder which won't appear on leaderstats
	hs.Name = "HiddenStats"

	local coinsValue = Instance.new("IntValue", ls)
	coinsValue.Name = "Coins"
	coinsValue.Value = coins

	local winsValue = Instance.new("IntValue", ls)
	winsValue.Name = "Wins"
	winsValue.Value = wins

	local skipsValue = Instance.new("IntValue", ls)
	skipsValue.Name = "Skips"
	skipsValue.Value = skips
	skipsValue.Parent = hs -- Parent the skip value to the hidden stats




	local ownedFolder2 = Instance.new("Folder", plr)
	ownedFolder2.Name = "OwnedTools"



	for i, owned in pairs(toolsOwned) do

		if tools:FindFirstChild(owned) then

			tools[owned]:Clone().Parent = ownedFolder2
		end
	end
end)

I have no idea if this is being saved by datastore.

Then make it so it is?
(29+1 characters)

instead of putting it under ls (the varibale you used for leaderstat), simply put it under player (or plr), so instead of

local skipsValue = Instance.new("IntValue", ls)
	skipsValue.Name = "Skips"
	skipsValue.Value = skips

do

local skipsValue = Instance.new("IntValue", plr)
	skipsValue.Name = "Skips"
	skipsValue.Value = skips

an explanation would be that leaderstat means leaderboard stats im guessing, and if you put it under player instead, it wouldn’t be shown on the leaderboard

this should work but if it doesn’t then it means I literally just missed something lol

As suggested here. Use attributes to store stats that you don’t want displayed.

--SAVING
local Attributes = leaderstats:GetAttributes()
for _, Child in ipairs(leaderstats:GetChildren()) do
	Attributes[Child.Name] = Child.Value
end
--Save 'Attributes' table to datastore here.

--LOADING
for Key, Value in pairs(Data) do --Loaded data.
	local Stat = leaderstats:FindFirstChild(Key) --Find stat inside leaderstats folder.
	if Stat then --If stat exists.
		Stat.Value = Value --Set stat's value to stored value.
	else --If stat doesn't exist.
		leaderstats:SetAttribute(Key, Value) --Set an attribute in the leaderstats folder.
	end
end

This is just pseudo-code, don’t copy and paste it expecting it to work.

1 Like