Leaderstsat does not show up

Hello I am Aidanmatt72 and I am trying to make a time based leveling leaderstat that saves

The issue i have is that the Leaderstsat does not show up

I have not tried any solutions as i know nothing about scripting
Here is my script

-- local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("LevelStats") -- Change this with a different name.

function onPlayerEntered(newPlayer)

	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local cash = Instance.new("IntValue")
	cash.Name = "Level (Testing)"
	cash.Value = 1

	cash.Parent = stats
	stats.Parent = newPlayer

while true do
		wait(600)
		cash.Value = cash.Value + 1
	



game.Players.ChildAdded:connect(onPlayerEntered)

	
	
	game.Players.PlayerRemoving:Connect(function(Player)
		end)
	DataStore:SetAsync(Player.UserId, {
		["Level"] = Player.leaderstats.Level.Value; -- Change "Level" with your currency.
	})
		
	end
end

Because leaderstats is supposed to be a folder.

-- local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("LevelStats") -- Change this with a different name.

function onPlayerEntered(newPlayer)

	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"

	local cash = Instance.new("IntValue")
	cash.Name = "Level (Testing)"
	cash.Value = 1

	cash.Parent = stats
	stats.Parent = newPlayer

while true do
		wait(600)
		cash.Value = cash.Value + 1
	



game.Players.ChildAdded:connect(onPlayerEntered)

	
	
	game.Players.PlayerRemoving:Connect(function(Player)
		end)
	DataStore:SetAsync(Player.UserId, {
		["Level"] = Player.leaderstats.Level.Value; -- Change "Level" with your currency.
	})
		
	end
end

This gives an in-depth answer on how to make leaderstats: In-Experience Leaderboards | Roblox Creator Documentation. Let me know if this works!

The Leaderstats are meant to be a folder as there will be values stored inside it.

1 Like

I pasted the changed script and got the same result in my testing map (there are no other scripts) here is a screen shot i took

can you send a screenshot inside of your player in explorer?

The script SHOULD be in ServerScriptService with API Services ENABLED to actually get data.

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("Stats")

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

	local Level = Instance.new("IntValue")
	Level.Name = "Level"
	Level.Value = 1

	Level.Parent = stats
	stats.Parent = Player

	while true do task.wait(600)
		Level.Value += 1
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId, {
		["Level"] = Player.leaderstats.Level.Value,
	})
end)

I made your code better, but you still have problems that you should consider fixing

  1. choose a name, is it level or cash
  2. UpdateAsync should be used
  3. BindToClose should be used

I am not going to do all of these for you

and make sure this is enabled as well

Ok so I do one final google search on the matter AND FIND AN ACTUAL WORKING SCRIPT of what i was looking for How do I make a time played leaderboard that SAVES Data? sorry for any inconvinience