Specific tools not allowed (ranks)

I want to make it so if a group rank (like 3-255) holds a specific item it would keep it in their inventory, however, if a guest picks it up or acquires it in their inventory it will destroy/deletes it from them. (Not allowed to hold the tool)

I’m hoping if there’s a source out there I can look or read to make this work. Hopefully, I can make it because I have no clue. I don’t have anything done, but if there’s a source out there I can read and check out it would help me a bunch.

Perhaps

this might help you this function will check on what rank if they are on the group

here is a default code from the dev hub

game.Players.PlayerAdded:Connect(function(Player)
    if Player:GetRankInGroup(2) == 255 then -- change 2 to your group ID
        print("Player is the owner of the group, 'LOL'!")
    else
        print("Player is NOT the owner of the group, 'LOL'!")
    end
end)

Let me see what I can do to make this work.

I believe that I need to replace the two-line with print
and add a script where “tool1” if rank it would stay in their inventory.

While

If not rank the “tool1” disappear/destroy from their inventory.

Where can I gather this information from a different source & thank you for the source.

you could do a function

tool.Handle.Touched:Connect(function(hit)
      local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
      if plr then -- if they exist
            if plr:GetRankInGroup(1) == 255 then -- change 1 to your group ID and 255 to your desired rank
                  hit.Parent:FindFirstChild("Humanoid"):EquipTool(tool)
            else
                  tool:Destroy()
            end
      end
end)

Alright let me go check it out.

Alright so it’s not working, I have “tool” in my starterpack (just for testing) & my localscript with the function inside of serverscriptservice.

When my alt join that isn’t in my group. The alt still obtain the “tool”

Did it work?

30char minimum

No, it didn’t work sadly. The alt spawned with the “tool” when it joined.

errors?

30char30char30char

Unknown Global ‘tool’ that’s an error

As well for “Unknown global ‘LoadLibrary’” & “Global ‘guiMain’ is only used in the enclosingfunction;consider changing it to local”

Yea just those errors are popping up.

in case i suggest putting this script inside a tool the part’ name must be handle or else it wont work

sorry for late reply by the way

local tool = script.Parent

tool.Handle.Touched:Connect(function(hit)
      local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
      if plr then -- if they exist
            if plr:GetRankInGroup(1) == 255 then -- change 1 to your group ID and 255 to your desired rank
                  hit.Parent:FindFirstChild("Humanoid"):EquipTool(tool)
            else
                  tool:Destroy()
            end
      end
end)