Attempt to index nil with 'GetRankInGroup'

Hello. New developer here, a script of which you can retrieve a tool from a GUI text button is what I was thinking about. At least that’s how I feel as far as I know for sure that my friend has handled it before. He has played the game a while ago and when he last played, everything was okay; not until he realized that none of the developer’s tools came up in his inventory. I checked on any errors appearing in Studio’s console, as well as trying out some things before running into this issue when using in-game console.

Players.Pixel10GamerLol.PlayerGui.ScreenGui.Frame.ImageLabel_Two.Eco.TextButton.Script:5: attempt to index nil with 'GetRankInGroup'  -  Server - Script:5

If anybody could tell me how to fix this, it would be amazing. Thanks!
This is the script.

local player = game.Players.LocalPlayer
local scriptParent = script.Parent

	if player:GetRankInGroup(34242595) == 1 then
		local economyClass = game.ReplicatedStorage:FindFirstChild("EconomyClass")
		if economyClass then
			local clone = economyClass:Clone()
			clone.Parent = player.Backpack

im too lazy to make a longass post so:
firstly, LocalPlayer is only available on the client side, and it looks like your script may be running on the server
secondly, it’s always better practice to use :GetService() instead of directly referencing services

so how to access the player on the serverside? well try one of these:

  1. local player = game:GetService("Players").PlayerAdded:Wait()
  2. do #1 but directly put code under playerevent like this:
    -- poopoo idk
  1. using RemoteEvents (i dont do this cs im a lazy person)
    LocalScript side:
game:GetService("ReplicatedStorage"):WaitForChild("omgomgomg a remote event!!"):FireServer()
  1. if it’s supposed to be childed to the character, then u could do this:
local player = game:GetService("Players"):GetPlayerFromCharacter(script.Parent)

kinda tinky winky
anyway mark as solution if i helped

edit: another thing i wanted to mention, since ur using a ui button, you can js use scriptParent.Activated instead of MouseButton1Click but ok

1 Like

Thank you so much! I’ll try it later.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.