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

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

Asked by
Zero_Tsou 175
5 years ago
Edited 5 years ago

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?

0
Likely because you're doing this in a SERVER script. The LOCAL player is available only in LOCAL scripts. DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by
Cyrakohl 108
5 years ago
Edited by User#24403 5 years ago

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!

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. User#24403 69 — 5y
Ad

Answer this question