Roblox Wiki
Advertisement
Roblox Wiki
Tutorial page
This article is an intermediate tutorial.

In this tutorial, we will make a script that will give players a tool based on what rank they are in a group. ROBLOX contains a built in function called 'GetRankInGroup()' that we will be using.

The Group[]

Whenever a role is created in a group, it is assigned to a number, called the Rank. This number is 0–255, and is vital for this tutorial. GetRankInGroup returns the rank that the player it is called on is in a group. The 0 rank is if the player is NOT in the group, and the 255 rank is the owner of the group. For this tutorial, we will use The LOL group, made by Shedletsky. This group has 5 roles.

Role Rank
Guest 0
Cheezburgers 1
Lieutenant of LOL 253
LOLCATS 254
God of LOL 255

The Scripting[]

Lets say we have a Tool light iconTool dark iconTool called "God Sword", located in ServerStorage light iconServerStorage dark iconServerStorage. We want this tool to be given to a player if they're the "God of LOL". We want this tool to be given immediately when a player joins. Create a Script light iconScript dark iconScript and put it in ServerScriptService light iconServerScriptService dark iconServerScriptService.

game.Players.PlayerAdded:Connect(function(plr)
if plr:GetRankInGroup(2) == 255 then --2 is the ID of the LOL group.
   local tool = game.ServerStorage["God Sword"]:Clone() -- Clones the God Sword.
   tool.Parent = plr:WaitForChild("Backpack") -- Wait for the player's Backpack to load, and puts the tool into it.
end
end)

This code will make a tool if the player is rank 255 in the LOL group. What if we have a tool called "Guide" and we only want "Cheezburgers" to have this tool? We do the same thing, by appending an elseif statement onto the same code.

game.Players.PlayerAdded:Connect(function(plr)
if plr:GetRankInGroup(2) == 255 then
   local tool = game.ServerStorage["God Sword"]:Clone()
   tool.Parent = plr:WaitForChild("Backpack")
elseif plr:GetRankInGroup(2) == 1 then
    local tool = game.ServerStorage.Guide:Clone()
    tool.Parent = plr:WaitForChild("Backpack")
end
end)
Advertisement