Not Showing Leaderstats when using DataStore2

When i use DataStore2 my leaderstats dont appear

Without DataStore2

With DataStore2

want my code here

local DataStore2 = require(game.ServerStorage:WaitForChild(“DataStore2”))
local DEFAULTS = 15

game.Players.PlayerAdded:Connect(function(player)
local blades = DataStore2(“blades”, player)
local bladesSt = DataStore2(“bladesSt”, player)
local coins = DataStore2(“coins”, player)

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

local Blades = Instance.new("IntValue")
Blades.Name = "Blades"

local BladesSt = Instance.new("IntValue")
BladesSt.Name = "BladesSt"
BladesSt.Parent = Blades

local Coins = Instance.new("IntValue")
Coins.Name = "Coins"

Blades.Parent = Fold
Coins.Parent = Fold

local function bladesUpdate(blades)
	Blades.Value = blades:Get(Blades)
end

local function bladesStUpdate(bladesSt)
	BladesSt.Value = bladesSt:Get(BladesSt)
end

local function coinsUpdate(coins)
	Coins.Value = coins:Get(coins)
end


bladesSt(DEFAULTS)

bladesUpdate:Set()

bladesStUpdate:Set()

coinsUpdate:Set()

end)

results

Player >
playerName >
No leaderstats

expected results

Player >
playerName >
With leaderstats

1 Like

Can you try to use this fixed code and tell me the results please?
You also should have a BoolValue named “SaveInStudio” turned to true in ServerStorage if you are trying to test it in studio.

local DataStore2 = require(game.ServerStorage:WaitForChild('DataStore2'))

local DEFAULTS = 15

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

local blades = DataStore2('blades', player)

local bladesSt = DataStore2('bladesSt', player)

local coins = DataStore2('coins', player)

local Fold = Instance.new("Folder")

Fold.Name = "leaderstats"

Fold.Parent = player

local Blades = Instance.new("IntValue")

Blades.Name = "Blades"

local BladesSt = Instance.new("IntValue")

BladesSt.Name = "BladesSt"

BladesSt.Parent = Blades

local Coins = Instance.new("IntValue")

Coins.Name = "Coins"

Blades.Parent = Fold

Coins.Parent = Fold

local function bladesUpdate(BladesUpdteValue)

Blades.Value = blades:Get(BladesUpdteValue)

end

local function bladesStUpdate(BladeStUpdateValue)

BladesSt.Value = bladesSt:Get(BladeStUpdateValue)

end

local function coinsUpdate(CoindUpdateValue)

Coins.Value = coins:Get(CoindUpdateValue)

end

bladesStUpdate(DEFAULTS)
bladesSt:OnUpdate(bladesStUpdate)

blades:OnUpdate(bladesUpdate)
coins:OnUpdate(coinsUpdate)

end)

Lemme try if it works if not then this is not the case

Where did u get those 3 parameters in each function

I am a little bit confused about what exactly we are talking about.

we are talking about why does my leaderstats does not show when i use DataStore2

Do you get any error in output?

Well, you’re setting the data after getting it.

And you’re not calling the function to set it.

Also, why are you putting the BladeSt inside Blades?

local DataStore2 = require(game.ServerStorage:WaitForChild("DataStore2"))
local DEFAULTS = 15

function playerAdded(player)
	local blades = DataStore2("blades", player)
	local bladesSt = DataStore2("bladesSt", player)
	local coins = DataStore2("coins", player)

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

	local Blades = Instance.new("IntValue")
	Blades.Name = "Blades"
	Blades.Value = blades:Get(0)  -- there's no need for a function, you can hook to a getpropertychangedsignal on the client
	-- the only reason why the docs have a function it to get changes
	Blades.Parent = Fold

	blades:OnUpdate(function(value) -- hook to onupdate, because when you update with datastore2 you use functional methods, you don't update value objects
		-- you would use methods like :Increment(-value) when purchasing items (you lose money when you buy stuff)
		Blades.Value = value
	end)

	local BladesSt = Instance.new("IntValue")
	BladesSt.Name = "BladesSt"
	BladesSt.Value = bladesSt:Get(DEFAULTS)
	BladesSt.Parent = Blades -- Why is it originally inside blades?

	bladesSt:OnUpdate(function(value)
		BladesSt.Value = value
	end)

	local Coins = Instance.new("IntValue")
	Coins.Name = "Coins"
	Coins.Value = coins:Get(0)
	Coins.Parent = Fold

	coins:OnUpdate(function(value)
		Coins.Value = value
	end)
end

for _, player in pairs(game.Players:GetPlayers()) do
	playerAdded(player)
end

game.Players.PlayerAdded:Connect(playerAdded)
1 Like

@mobyboyy for storage capacity

Can you explain what you mean by that?

as you can see im making a simulator with backpack capacity so when my blades = bladesSt.Value

Ok, should be fixed, try my code now.

i think it should work ok lets test it

Any reason for why you unmarked it?

Mind providing screenshots?

havent try i cant use studio right now provide viddeos or screenshots if posible @mobyboyy

I can’t use studio either. So I’m also unable to do that.

omg thank you it worked i appreciate your help

1 Like