Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm trying to script a leaderboard and I'm new to scripting and I'm not sure what i did wrong?

local Players = game:GetService("Players")

local function leaderboardSetup(player)

end

-- Connect the "leaderboardSetup()" function to the "PlayerAdded" event Players.PlayerAdded:Connect(leaderboardSetup)

the word "game" was red

2 answers

Try this:

game.Players.PlayerAdded:Connect(function(player)
	
	local leaderstats = Instance.new("Folder") --or ("Folder",player)
	leaderstats.Parent = player --remove this if you did ("Folder",player)
	leaderstats.Name = "leaderstats" --Don't change this 
	
	local Points = Instance.new("IntValue") --or ("IntValue", leaderstats)
	Points.Parent = leaderstats --remove this if you did ("Folder",player)
	Points.name = "Points"
  	Points.Value = 5 --You can change the value
end)

--You can change Points to any name.

Make sure that the script is inside ServerScriptService Make sure it's script and not local script.

2 comments

0

thank you! that worked

0

no problem, also check the second answer for the explanation if you want

I'm not sure what you're trying to achieve here, but I'll show an example on how to create a leaderboard.

local Players = game:GetService("Players")

Players.PlayerAdded:connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local points = Instance.new("IntValue", leaderstats)
	points.Name = "Points"
	points.Value = 0
end)

"PlayerAdded" is an event to detect if a player joined, and I'm connecting it to the function. Next you want to create a folder with the name "leaderstats" to be detected as a leaderboard for roblox's built in leaderboard system. You can then create values and parent them to the leaderboard to be displayed. I recommend reading about how functions and leaderboards work on the roblox wiki, here's some links.

https://developer.roblox.com/en-us/articles/Function

https://developer.roblox.com/en-us/articles/Leaderboards

This discussion is preserved as it was. New answers, comments, and votes are closed.