Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
thank you! that worked lilystyle10 0 — 4y
0
no problem, also check the second answer for the explanation if you want Flasker917 21 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question