Leaderstats not importing the data into a value in a leaderstats folder

Hi cookie tech :cookie: So I am trying to set up some leaderstats but when someone joins the game the leaderstats are ethier - or people only get one leaderstat and not the other.

How can I make two leaderstats like this? These are the scripts!

Rank:

local GroupID = 5122099		-- Id of group; is found in the URL/link
local CharHide = 0			-- Amount of characters from the beginning of rank name to hide.  
							-- Useful if role has numbers or HR/LR in it, and you don't want it in game.

game:GetService('Players').PlayerAdded:Connect(function(p)
	local ls = Instance.new('IntValue', p)
	ls.Name = 'leaderstats'
	local rank = Instance.new('StringValue', ls)
	rank.Name = 'Rank'
	rank.Value = 'Guest'
	if p:IsInGroup(GroupID) then
		local xrole = p:GetRoleInGroup(GroupID)
		if string.len(xrole) <= CharHide then
			warn('[GroupLeaderboard] Attempted to hide more characters than role has; using default name')
			rank.Value = xrole
		else
			local role = string.sub(xrole, CharHide+1)
			rank.Value = role
		end
	end
end)

Money:

-- For a documentation on DataStore2, read this: https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317

local ds2 = require(game.ServerScriptService:WaitForChild("DataStore2"))
local defaultValue = script:GetAttribute("DefaultValue")

game.Players.PlayerAdded:Connect(function(plr)
	local ds = ds2("MoneySave", plr)
	
	local leader = Instance.new("Folder", plr)
	leader.Name = script:GetAttribute("FolderName")
	
	local m = Instance.new("IntValue", leader)
	m.Name = script:GetAttribute("CurrencyName")
	
	local updateValue = function(updatedValue)
		m.Value = ds:Get(updatedValue)
	end
	
	updateValue(defaultValue)
	
	ds:OnUpdate(updateValue)
end)

game.ReplicatedStorage:WaitForChild("RobberyAddValue").Event:Connect(function(plr, value)
	local dataStore = ds2("MoneySave", plr)
	dataStore:Increment(value, defaultValue)
end)
1 Like

Are these supposed to be saving?

The money one yes.

20

Just duplicate the value and paste it into the leaderstats folder, then dont save it.

Can you rename your title to be more descriptive too please?

So that didnt help, I need the the leaderstats to show, the money one only shows or the rank one only shows, they dont both show. @cookie

1 Like

Okay, once I’m back on my device I’ll show you a feasible way to do this!

1 Like

Please do this first, the issue is you’re not importing the data into a value in a leaderstats folder.

1 Like

You’ll ned to import an integer value into the leaderstats for this to work.


Please mark this as solution if it fixes your problem.

error
Does not seem to be working.

Ah, no, you’ll need to insert it via the script.

How would I go about that?

   value = Instance.new("IntValue")
   value.Parent = workspace.x

Something along the lines of this.

Like this?

local GroupID = 5122099		-- Id of group; is found in the URL/link
local CharHide = 0			-- Amount of characters from the beginning of rank name to hide.  
							-- Useful if role has numbers or HR/LR in it, and you don't want it in game.

game:GetService('Players').PlayerAdded:Connect(function(p)
	local ls = Instance.new('IntValue', p)
	ls.Name = 'leaderstats'
	local rank = Instance.new('StringValue', ls)
	rank.Name = 'Rank'
	rank.Value = 'Guest'
	if p:IsInGroup(GroupID) then
		local xrole = p:GetRoleInGroup(GroupID)
		if string.len(xrole) <= CharHide then
			warn('[GroupLeaderboard] Attempted to hide more characters than role has; using default name')
			rank.Value = xrole
		else
			local role = string.sub(xrole, CharHide+1)
			rank.Value = role
			-- For a documentation on DataStore2, read this: https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317

			local ds2 = require(game.ServerScriptService:WaitForChild("DataStore2"))
			local defaultValue = script:GetAttribute("DefaultValue")

			game.Players.PlayerAdded:Connect(function(plr)
				local ds = ds2("MoneySave", plr)

				local leader = Instance.new("Folder", plr)
				leader.Name = script:GetAttribute("FolderName")

				local m = Instance.new("IntValue", leader)
				m.Name = script:GetAttribute("CurrencyName")

				local updateValue = function(updatedValue)
					m.Value = ds:Get(updatedValue)
				end

				updateValue(defaultValue)

				ds:OnUpdate(updateValue)
			end)

			game.ReplicatedStorage:WaitForChild("RobberyAddValue").Event:Connect(function(plr, value)
				local dataStore = ds2("MoneySave", plr)
				dataStore:Increment(value, defaultValue)
			end)	
		end
		
	end
end)
value = Instance.new("IntValue")
value.Parent = workspace.x
-- For a documentation on DataStore2, read this: https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317

local ds2 = require(game.ServerScriptService:WaitForChild("DataStore2"))
local defaultValue = script:GetAttribute("DefaultValue")

game.Players.PlayerAdded:Connect(function(plr)
	local ds = ds2("MoneySave", plr)
	
	local leader = Instance.new("Folder", plr)
	leader.Name = script:GetAttribute("FolderName")
	
	local m = Instance.new("IntValue", leader)
	m.Name = script:GetAttribute("CurrencyName")
	
	local updateValue = function(updatedValue)
		m.Value = ds:Get(updatedValue)
	end
	
	updateValue(defaultValue)
	
	ds:OnUpdate(updateValue)
end)

game.ReplicatedStorage:WaitForChild("RobberyAddValue").Event:Connect(function(plr, value)
	local dataStore = ds2("MoneySave", plr)
	dataStore:Increment(value, defaultValue)
end)
value = Instance.new("IntValue")
value.Parent = workspace.x

Try merging them both into one script.

Something along those lines, but you can’t copy and paste it, you’ll need to customize the parent of the integer to the leaderstats folder in the player.

I can’t copy and paste the scripts?

No, as I don’t know how your configuration is.

You can use similar code, but it can’t be the exact same.

Configuration is the same.

That’s not what I meant, also, there is no point of me spoon-feeding.