Tools for specific rank not working

The script goes into the specific tool and then I move the tool into a specific team (I have a team tool script). It works the only problem is that if I do <4 none of the ranks under “4” get the tool but every rank above “4” so 5,6,7,8 etc… get it. How do I make it werre only that specific rank can get the tool. I need it written like it is now to make it simple for me. So I can just drag the script into the tool and put it the team I desire.

Current Script

wait()

if game.Players.LocalPlayer:GetRankInGroup(123456) < 1 and script.Parent.ClassName ~= “Team” then

script.Parent:remove()

end

I’ve tried to change it to >= instead of < but it has the opposite effect: example => 4 | It’ll give all the tools to ranks under 4 but not to ranks above 4…

2 Likes

If you want to check if they are a certain rank, use an ==

if game.Players.LocalPlayer:GetRankInGroup(123456) == 4 then
--code
end

if you want to check if they are higher than a certain rank, do this:

if game.Players.LocalPlayer:GetRankInGroup(123456) > 4 then
--code
end
3 Likes

I will try this out, thank you!

3 Likes

in a server script

local groupId = 0--the group id
game.Players.PlayerAdded:Connect(function(plr)
 -- get rank
 local rank = plr:GetRankInGroup(groupId)
 if rank >= 4 then
  local tool = game.ServerStorage.Tool:Clone() -- the path of tool, this assumes its in server storage
  tool.Parent = plr.Backpack
 else
  print("nah")
 end
end)

EDIT: It’s bad practice to do important things on the client, if you can do it on the server it’s probably better to not use the client

3 Likes

Is it able to be targetted to a specific team, so only a specific team → group → rank gets the tool?

1 Like

yeah, just replace the if with

if plr.Team == "team name" then 
 -- do stuff
end
3 Likes

You are able to do this by adding an and to the if function.
(using @Sniperkaos code)

local groupId = 0--the group id
game.Players.PlayerAdded:Connect(function(plr)
 -- get rank
 local rank = plr:GetRankInGroup(groupId)
 if rank >= 4 and plr.Team == game:GetService("Teams")["Team Name"] then
  local tool = game.ServerStorage.Tool:Clone() -- the path of tool, this assumes its in server storage
  tool.Parent = plr.Backpack
 else
  print("nah")
 end
end)

Keep in mind this script runs as soon as the player joins, so you may need to set their team before this, or just run this code when they join the specified team.

1 Like

Sorry, if this is a dumb question but what do I do if I want to add multiple tools to one rank? Do I just copy and paste the same script but change the tool name?

2 Likes

you can copy and paste this and change the ‘Tool’ to whatever the name of the other tool is:

 local tool = game.ServerStorage.Tool:Clone() -- the path of tool, this assumes its in server storage
 tool.Parent = plr.Backpack
1 Like