Hi, So I’m wondering how I would make a Group Rank Team tools, for example:
Player goes on Army(Team name) Team.
Their rank is 5+(ID) in the group.
They get their tool(s).
If their not 5+, they do not get their tools.
Please help me with making this. Thank you!(I can’t find any way to learn this on video tutorials.)
Note: I’m very new at scripting!
You’d first want to create the Teams service by finding the “Insert Service” button inside Studio:
You can call this nifty function called: Player:GetRankInGroup() which returns back the Rank Number they’re currently in (In addition with a PlayerAdded event)
You could reference the Tools inside a Folder in ServerStorage, use GetChildren() which returns back a table of all the Tools stored in that “Folder”, and again calling GetRankInGroup() would give you the Rank Number so you could check if the Player has a rank that’s higher than 5 or more, clone the tools then parent them to their Backpack/StarterGear
Code example? Keeping in mind this is a Script in ServerScriptService:
local GroupID = 0000 --Replace this with your GroupID here
local Tools = game.ServerStorage:WaitForChild("Tools"):GetChildren() --Returns back a table
local ToolRequirement = 5
game.Players.PlayerAdded:Connect(function(Player)
local PlayerRank = Player:GetRankInGroup(GroupID) --This would return a number
if PlayerRank >= ToolRequirement then --Check if the PlayerRank is greater or equal than 5
for _, Tool in pairs(Tools) do
Tool:Clone().Parent = Player.Backpack
Tool:Clone().Parent = Player.StarterGear
end
end
end)
Okay, so it does work. But, I want them to be on the “Army” team for them to get the Tool, currently when I run studio I instantly get it without being on the Army Team.
You could just check if the Player’s Team is equal to the Team that you’re searching for, try this:
local Teams = game:GetService("Teams")
local Army = Teams:WaitForChild("Army")
local GroupID = 0000 --Replace this with your GroupID here
local Tools = game.ServerStorage:WaitForChild("Tools"):GetChildren() --Returns back a table
local ToolRequirement = 5
game.Players.PlayerAdded:Connect(function(Player)
local PlayerRank = Player:GetRankInGroup(GroupID) --This would return a number
if PlayerRank >= ToolRequirement and Player.Team == Army then --Check if the PlayerRank is greater or equal than 5
for _, Tool in pairs(Tools) do
Tool:Clone().Parent = Player.Backpack
Tool:Clone().Parent = Player.StarterGear
end
end
end)
Although, it depends on when you want them to exactly give the tools
The code provided has the material needed for cloning, however, since you want to clone the items when they switched to the Army Team, you’d need to utilise :GetPropertyChangedSignal(plr.Team). (before his second post)
local groupId = 0000 --your groupId
local army = game:GetService("Teams").Army
local tools = game.ServerStorage:WaitForChild("Tools"):GetChildren() --put all your tools in the "Tools" folder in ServerStorage
local minRank = 5 --which rank id can start using it
game.Players.PlayerAdded:Connect(function(plr) --player connected
plr:GetPropertyChangedSignal(plr.Team):Connect(function() --listens to when their Team has changed
if plr.Team == army and plr:GetRankInGroup(groupId) >= minRank then
--if the player is in Army and is above rank id of 5 then
for _, tool in pairs(tools) do --for every tool in the folder do
Tool:Clone().Parent = Player.Backpack --put in the player's backpack
Tool:Clone().Parent = Player.StarterGear --put in the player's startergear
end
end
end)
end)
local groupId = 0000 --your groupId
local army = game:GetService("Teams").Army
local tools = game.ServerStorage:WaitForChild("Tools"):GetChildren() --put all your tools in the "Tools" folder in ServerStorage
local minRank = 5 --which rank id can start using it
local function checkIfInArmy(plr)
if plr.Team == army and plr:GetRankInGroup(groupId) >= minRank then
--if the player is in Army and is above rank id of 5 then
for _, tool in pairs(tools) do --for every tool in the folder do
Tool:Clone().Parent = Player.Backpack --put in the player's backpack
end
end
end
game.Players.PlayerAdded:Connect(function(plr) --player connected
if plr:GetRankInGroup(groupId) >= minRank then
plr.Team = army
end
plr:GetPropertyChangedSignal(plr.Team):Connect(function() --listens to when their Team has changed
checkIfInArmy(plr)
end)
plr.CharacterAdded:Connect(function(char) --each time they respawned
checkInInArmy(plr)
end)
end)
This is not working
game.Players.PlayerAdded:Connect(function(plr) --player connected
if plr:GetRankInGroup(groupId) >= minRank then
plr.Team = army
“plr.Team = army” it seems that it’s teaming them army, I want them if their on the team and reset it will give them the tool.
So, GetPropertyChangedSignal is an event that would fire a function whenever that specific property of the Instance changes (Let’s say, the Player’s Team)
In addition to what @Doqee stated, you can add this with a CharacterAdded Event as well which would frequently check the Player’s Team whenever it both changes, and when a Character Model gets added to the game (Since we’re calling the CharacterAdded event, we don’t need to reference the Player’s StarterGear)
local Teams = game:GetService("Teams")
local Army = Teams:WaitForChild("Army")
local GroupID = 0000 --Replace this with your GroupID here
local Tools = game.ServerStorage:WaitForChild("Tools"):GetChildren() --Returns back a table
local ToolRequirement = 5
local function CheckTeam(Player)
local PlayerRank = Player:GetRankInGroup(GroupID) --This would return a number
if PlayerRank >= ToolRequirement and Player.Team == Army then --Check if the PlayerRank is greater or equal than 5
for _, Tool in pairs(Tools) do
Tool:Clone().Parent = Player.Backpack
end
end
end
game.Players.PlayerAdded:Connect(function(Player)
CheckTeam(Player)
Player.CharacterAdded:Connect(function(Character)
CheckTeam(Player)
end)
Player:GetPropertyChangedSignal("Team"):Connect(function()
CheckTeam(Player)
end)
end)