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
6 years ago
Edited 6 years ago

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

01game.Players.PlayerAdded:Connect(function(player)
02local leaderstats= Instance.new("Folder")
03leaderstats.Name = "leaderstats"
04leaderstats.Parent = player
05local Ranking = Instance.new("StringValue")
06Ranking.Name = "Rank"
07Ranking.Value = game.Players.LocalPlayer:GetRoleInGroup(2580112)
08Ranking.Parent = leaderstats
09 
10end)

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 — 6y

1 answer

Log in to vote
0
Answered by
Cyrakohl 108
6 years ago
Edited by User#24403 6 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!

1local GroupID = IDHERE -- Change "IDHERE" To your group ID 
2 
3game.Players.PlayerAdded:Connect(function(Player)
4end)

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!

01local GroupID = IDHERE
02 
03game.Players.PlayerAdded:Connect(function(Player)
04 
05    local leaderstats = Instance.new("Folder")
06    leaderstats.Name = "leaderstats"
07    leaderstats.Parent = Player
08 
09    local Role = Instance.new("StringValue")
10    Role.Name = "Role"
11    Role.Value = Player:GetRoleInGroup(GroupID)
12    Role.Parent = leaderstats
13end)

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 — 6y
Ad

Answer this question