Problem with GetRankInGroup

So I am trying to make a Over-head gui for all the group ranks, but it gives me this error:
19:54:31.235 - ServerScriptService.OverHeadGuiScript:6: attempt to index nil with ‘GetRankInGroup’

I’ve seen other post on this problem but it was for all ranks above a certain number, but with mine is every rank.

This is a small part of the script(there is a whole bunch of elseif’s for the other ranks.):

if Player:GetRankInGroup(6783583) == 255 then
			local ClonedGui = OverHeadGui:Clone()
			ClonedGui.Parent = game.Workspace:WaitForChild(plr.Name).Head
			ClonedGui.Label.Text = "Owner"

Thank you for reading!

2 Likes

first of all. Put the result in a variable. Second of all, the error means that Player doesn’t exist

Most of the time the error message should tell you what is wrong.

How are you defining the Player variable?

I’m using:

local Player = game.Players.LocalPlayer

What do you mean by that? What is the result?

Is this a server script? You can only use game.Players.LocalPlayer in a local script.

2 Likes

Server or local script? tHe result is what Player:GetRankInGeoup() returns

Don’t do this on a local script, do it on a server script and use the .CharacterAdded event

1 Like

It is a server script(30charsss)

LocalPlayer doesn’t work in Server Scripts. As @topdog_alpha said. Use playeradded

It is within a CharacterAdded event.

Sorry guys, i got it to work!
It was in a player.added event so i used the perimeter.

1 Like

Your script would want to be a server script and look like this:

game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
-- UI stuff goes in here
end)
plr:LoadCharacter()
end)

You may find that you have to reset at least once to get the UI to appear on the player due to the .CharacterEvent not firing when a player is first added (roblox issue don’t ask lol) but the work around to this is by putting plr:LoadCharacter() at the end of the PlayerAdded event (look where I put it in the above script) and this should trigger the characteradded event

I already did that. But thanks for the help.

In that case transfer this to a server script and it will work