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

Attempt to Index nil problem?

I have made a script to make a GUI only enabled to certain ranks but when I test it, it always comes up in output as ServerScriptService.Script:6: attempt to index nil with 'GetRoleInGroup'.

local role = 4

local groupId = 5868343

local player = game.Players.LocalPlayer
if player.GetRoleInGroup(groupId) >= role then
	player.PlayerGui.Handto.Enabled = true
end

1 comment

0

You have to use a : and you have to use Rank since thats the rank number, and Role is the role name. So, it's like this. if player:GetRankInGroup(groupId) >= role then

1 answer

The problem that's causing your error is that player does not exist. This is because you're trying to access LocalPlayer from the server, you can't do that. You can however access it from a LocalScript. When working with GUIs it's best to work from LocalScripts anyway, you could put it inside of the Gui or in a place like StarterPlayerScripts.

Another issue you'll run into is that GetRoleInGroup() returns a string, not the Rank ID. Instead, use player:GetRankInGroup(groupId) or player.GetRankInGroup(player, groupId)

1 comment

0

Thank you so much! Much appreciated.

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