Global Leaderboard Script Not Working

Hello Everyone!

So right now I am making an obby. (I’m ashamed to admit it but I was bored and they are fun to make)
I am currently trying to make a Global Leaderboard for coins, following a DevKing tutorial on Youtube. I have checked for any typos in the script, yet cannot find what is wrong. When I play the game I get this error

103: string is not allowed in data stores.  -  Server - LeaderboardHandler:39
   Stack Begin  -  Studio
   Script 'ServerScriptService.LeaderboardHandler', Line 39 

I do not know if it is because of maybe how my leaderstats is scripted, as this game I made a year ago and I really don’t know where I got anything from. I have looked for solutions and could not find any. The leaderstats script is coded weird and I didn’t know how to add coins into the datastore part of it, so I will include that script as well as the leaderboard script

Leaderboard Script:

local DataStoreService = game:GetService("DataStoreService")
local CoinsLeaderboard = DataStoreService:GetOrderedDataStore("CoinsLeaderboard")

local function updateLeaderboard ()
	local success, errorMessage = pcall(function()
		local Data = CoinsLeaderboard:GetSortedAsync(false, 5)
		local CoinsPage = Data:GetCurrentPage()
		for Rank, data in ipairs(CoinsPage) do
			local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = userName
			local Coins = data.value
			local isOnLeaderboard = false
			for i, v in pairs (game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
				if v.Player.Text == Name then
					isOnLeaderboard = true
					break
				end
			end

			if Coins and isOnLeaderboard == false then
				local newLBFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
				newLBFrame.Player.Text = Name
				newLBFrame.Rank.Text = "#"..Rank
				newLBFrame.Coins.Text = Coins
				newLBFrame.Position = UDim2.new(0, 0, newLBFrame.Position.Y.Scale + (.08 * #game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
				newLBFrame.parent = game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder	
			end
		end
	end)

	if not success then
		print(errorMessage)
	end
end

while true do

	for _, player in pairs(game.Players:GetPlayers()) do
		CoinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Coins.Value) --this is where i get the error...
	end

	for _, frame in pairs (game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
		frame:Destroy()
	end
	updateLeaderboard()
	print("Updated!")

	wait(10)
end

Leaderstats Script:

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("SaveData")


local function SavePlayerData(player)

	local success,errormsg = pcall(function()

		local SaveData = {}

		for i,stats in pairs(player.leaderstats:GetChildren()) do

			SaveData[stats.Name] = stats.Value
		end 
		SaveDataStore:SetAsync(player.UserId,SaveData)
	end)

	if not success then 
		return errormsg
	end   
end 


Players.PlayerAdded:Connect(function(player)

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

	local Stage = Instance.new("StringValue")
	Stage.Name = "Stage"
	Stage.Parent = Stats
	Stage.Value = 1
	local Coins = Instance.new("StringValue")
	Coins.Name = "Coins"
	Coins.Parent = Stats
	Coins.Value = 0

	local Data = SaveDataStore:GetAsync(player.UserId)
	
	
	--Everything under this I Have NO clue what any of it is and dont know how do add the coins into it...or if its even necessary.
	if Data then

		print(Data.Stage)

		for i,stats in pairs(Stats:GetChildren()) do

			stats.Value = Data[stats.Name]  
		end   
	else  
		print(player.Name .. " has no data.")   
	end


	player.CharacterAdded:Connect(function(character)

		local Humanoid = character:WaitForChild("Humanoid")
		local Torso = character:WaitForChild("HumanoidRootPart")

		wait()

		if Torso and Humanoid then
			if Stage.Value ~= 0 then

				local StagePart = workspace.Stages:FindFirstChild(Stage.Value)
				Torso.CFrame = StagePart.CFrame + Vector3.new(0,1,0) 
				
				
			end 
		end 
	end)  
end)


Players.PlayerRemoving:Connect(function(player)

	local errormsg = SavePlayerData(player)

	if errormsg then 
		warn(errormsg)  
	end 
end)

game:BindToClose(function()
	for i,player in pairs(Players:GetPlayers()) do 

		local errormsg = SavePlayerData(player)
		if errormsg then
			warn(errormsg)
		end   
	end
	wait(2) 
end)

I am partially a beginner, so please forgive me if this is an easy fix, or if it was done completely wrong…Really hope I can get this fixed.

Thank you!

1 Like

In your leaderstats script change the Coins instance to a IntValue. This should hopefully fix the issue.

1 Like

Where in it?? like replacing the string value? im tired…hehe

local Coins = Instance.new("IntValue")

Ohhhh ok, thanks ill test it right now

Hopefully, that works. Though I would recommend learning datastores since it will help a lot in the long run.

1 Like

Oh it works! thanks a lot. now it says parent isnt a valid member of leaderboardframe…lol

Where abouts is the error in the script?

doesnt say… just shows

13:51:38.884 parent is not a valid member of Frame “LeaderboardFrame” - Server
13:51:38.885 Updated! - Server

for the printing part of it.

oh wait i got it, was just because it was lowercase.

Oh nice! Does everything work now?

Yes, again thanks a lot.

303030

No worries, you should mark a solution just incase anyone has a similar issue in the future they can find it. Glad I could help!

Waaaaayyyyy ahead of you. :wink: (Already did lol)