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

How do you make a leaderstats that shows your Role in a Group?

I tried to think of this on my own and i got a solution but i have a small problem!

game.Players.PlayerAdded:Connect(function(player)
local leaderstats= Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Ranking = Instance.new("StringValue")
Ranking.Name = "Rank"
Ranking.Value = game.Players.LocalPlayer:GetRoleInGroup(2580112)
Ranking.Parent = leaderstats

end)

In the Output it's says an Error ( Workspace.Script:8: attempt to index field 'LocalPlayer' (a nil value) ) Why? I don't understand why it's a Nil value. Can you help me out please?

1 comment

0

Likely because you're doing this in a SERVER script. The LOCAL player is available only in LOCAL scripts.

1 answer

So first of all you cannot index local player in a server script only a local script.

So second of all we need to set up our Variable and our function as shown below!

local GroupID = IDHERE -- Change "IDHERE" To your group ID  

game.Players.PlayerAdded:Connect(function(Player)
end)

So Now we have that done now we need to create our leaderstats folder which is required to display leaderstats ingame! along with that we will make our role leaderstat in the process!

local GroupID = IDHERE 

game.Players.PlayerAdded:Connect(function(Player)

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

    local Role = Instance.new("StringValue")
    Role.Name = "Role"
    Role.Value = Player:GetRoleInGroup(GroupID)
    Role.Parent = leaderstats
end)

Hope this helped you!

1 comment

0

Use groupservice. GetRoleInGroup caches its result on the server. And don't do it client side either. You can't trust the client. Ever.

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