Why does it have a error

formatted code:

local Players = game:GetService(“Players”)
local ServerScriptService = game:GetService(“ServerScriptService”)

local Template = require(ServerScriptService.PlayerData.Template)
local Manager = require(ServerScriptService.PlayerData.Manager)
local ProfileService = require(ServerScriptService.Libs.ProfileService)

local ProfileStore = ProfileService.GetProfileStore(“2”, Template) – (1 = Test) (2 = Production)

local KICK_MESSAGE = “Could not find data Please rejoin If issue persists, contact us via group wall”

local function CreateLeaderStats(player: Player)
local profile = Manager.Profiles[player]
if not profile then return end

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

local coins = Instance.new("NumberValue", leaderstats)
coins.Name = "Clicks"
coins.Value = profile.Data.Clicks

local Gems = Instance.new("NumberValue", leaderstats)
Gems.Name = "Gems"
Gems.Value = profile.Data.Gems

end

local function LoadProfile(player: Player)
local profile = ProfileStore:LoadProfileAsync(“Player_”…player.UserId)
if not profile then
Players:Kick(KICK_MESSAGE)
return
end

profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
	Manager.Profiles[player] = nil
	Players:Kick(KICK_MESSAGE)
end)

if player:IsDescendantOf(Players) == true then
	Manager.Profiles[player] = profile
	CreateLeaderStats(player)
else	
	profile:Release()
end

end

for _, Player in Players:GetPlayers() do
task.spawn(LoadProfile, Players)
end

Players.PlayerAdded:Connect(LoadProfile)
Players.PlayerRemoving:Connect(function(Players)
local profile = Manager.Profiles[Players]
if profile then
profile:Release()
end
end)

Still nothing!?!? Idk why? But the leaderboard doesn’t say anything

type checking has nothing to do with the error, it will just signal the compiler or the IDE that it will probably be that variable, but not error (unless its on strict mode).

Sorry, I dont know what that means.

instead of putting the parent after instance.new(“thing”, parent)
try doing .Parent = Parent

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")

local Template = require(ServerScriptService.PlayerData.Template)
local Manager = require(ServerScriptService.PlayerData.Manager)
local ProfileService = require(ServerScriptService.Libs.ProfileService)

local ProfileStore = ProfileService.GetProfileStore("2", Template) -- (1 = Test) (2 = Production)

local KICK_MESSAGE = "Could not find data, please rejoin. If issue persists, contact us via group wall"

local function CreateLeaderStats(player: Player)
	local profile = Manager.Profiles[player]
	if not profile then return end

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

	local coins = Instance.new("NumberValue", leaderstats)
	coins.Name = "Clicks"
	coins.Value = profile.Data.Clicks

	local Gems = Instance.new("NumberValue", leaderstats)
	Gems.Name = "Gems"
	Gems.Value = profile.Data.Gems

	leaderstats.Parent = player
end

local function LoadProfile(player: Player)
	local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
	if not profile then
		Players:Kick(KICK_MESSAGE)
		return
	end

	profile:AddUserId(player.UserId)
	profile:Reconcile()
	profile:ListenToRelease(function()
		Manager.Profiles[player] = nil
		Players:Kick(KICK_MESSAGE)
	end)

	if player:IsDescendantOf(Players) == true then
		Manager.Profiles[player] = profile
		CreateLeaderStats(player)
	else	
		profile:Release()
	end

end

for _, Player in Players:GetPlayers() do
	task.spawn(LoadProfile, Players)
end

Players.PlayerAdded:Connect(LoadProfile)

Players.PlayerRemoving:Connect(function(Players)
	local profile = Manager.Profiles[Players]
	if profile then
		profile:Release()
	end
end)

This should work

Here is my full code

Script 1 - Template

local Template = {
Coins = 0
Gems = 0
}

return Template

Script 2 - Manager

local Manager = {}

Manager.Profiles = {}

return Manager

Script 3 - Data
local Players = game:GetService(“Players”)
local ServerScriptService = game:GetService(“ServerScriptService”)

local Template = require(ServerScriptService.PlayerData.Template)
local Manager = require(ServerScriptService.PlayerData.Manager)
local ProfileService = require(ServerScriptService.Libs.ProfileService)

local ProfileStore = ProfileService.GetProfileStore(“2”, Template) – (1 = Test) (2 = Production)

local KICK_MESSAGE = "Could not find data Please rejoin If issue persists, contact us via group wall”

local function CreateLeaderStats(player: Player)
local profile = Manager.Profiles[player]
if not profile then return end

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

local coins = Instance.new("NumberValue", leaderstats)
coins.Name = "Clicks"
coins.Value = profile.Data.Clicks

local Gems = Instance.new("NumberValue", leaderstats)
Gems.Name = "Gems"
Gems.Value = profile.Data.Gems

end

local function LoadProfile(player: Player)
local profile = ProfileStore:LoadProfileAsync(“Player_”…player.UserId)
if not profile then
Players:Kick(KICK_MESSAGE)
return
end

profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
	Manager.Profiles[player] = nil
	Players:Kick(KICK_MESSAGE)
end)

if player:IsDescendantOf(Players) == true then
	Manager.Profiles[player] = profile
	CreateLeaderStats(player)
else	
	profile:Release()
end

end

for _, Player in Players:GetPlayers() do
task.spawn(LoadProfile, Players)
end

Players.PlayerAdded:Connect(LoadProfile)
Players.PlayerRemoving:Connect(function(Players)
local profile = Manager.Profiles[Players]
if profile then
profile:Release()
end
end)

Nothing! Nothing on the leaderboard

Add a comma after the coins line in the Template script

local Template = {
Coins = 0,
Gems = 0
}

return Template
2 Likes

Thank you so much, It worked

Thank you so much everybody for helping me!

3 Likes

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