Group rank team tools

You can write your topic however you want, but you need to answer these questions:

  1. A team only group rank set of tools, it wordked before but it was giving tools to ALL the players that meet te requierments, but now i changed it a bit for only a team only. I did some playtest, nothing in the output.

  2. I can’t get this to work.

  3. I asked some friends, but nothing so far.

local Players = game:GetService("Players")
local GrpId = 0-- Already changed

local Items = {
	["WPN1"] = game.ServerStorage["AR"],
	["WPN2"] = game.ServerStorage["Pistol"],
	["WPN3"] = game.ServerStorage["SMG"],
}

local RankItems = {
	[150] = {"WPN1", "WPN2", "WPN3"},
	[160] = {"WPN1", "WPN2", "WPN3"},-- Team with 10 rank match
	[170] = {"WPN1", "WPN2", "WPN3"},
	[180] = {"WPN1", "WPN2", "WPN3"},
	[190] = {"WPN1", "WPN2", "WPN3"},
	[255] = {"WPN1", "WPN2", "WPN3"},
	
}

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		local GroupRank = Player:GetRankInGroup(GrpId)
		if Player.Team == game.Teams.Team then  -- Already changed.
		elseif RankItems[GroupRank] then
			for _, item in pairs(RankItems[GroupRank]) do
				Items[item]:Clone().Parent = Player.Backpack
			end
		end
	end)
end)

I think it would be better to make it work on player join for the tool giving. Also, you were doing Items[item] when item is the value returned, not the index.

If you just want a fix for your code, this is what you’d use

local Players = game:GetService("Players")
local GrpId = 0-- Already changed

local Items = {
	["WPN1"] = game.ServerStorage["AR"],
	["WPN2"] = game.ServerStorage["Pistol"],
	["WPN3"] = game.ServerStorage["SMG"],
}

local RankItems = {
	[150] = {"WPN1", "WPN2", "WPN3"},
	[160] = {"WPN1", "WPN2", "WPN3"},-- Team with 10 rank match
	[170] = {"WPN1", "WPN2", "WPN3"},
	[180] = {"WPN1", "WPN2", "WPN3"},
	[190] = {"WPN1", "WPN2", "WPN3"},
	[255] = {"WPN1", "WPN2", "WPN3"},
	
}

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		local GroupRank = Player:GetRankInGroup(GrpId)
		if Player.Team == game.Teams.Team then  -- Already changed.
		elseif RankItems[GroupRank] then
			for _, item in pairs(RankItems[GroupRank]) do
				item:Clone().Parent = Player.Backpack
			end
		end
	end)
end)

Although personally I think this is better since StarterGear exists

local Players = game:GetService("Players")
local GrpId = 0-- Already changed

local Items = {
	["WPN1"] = game.ServerStorage["AR"],
	["WPN2"] = game.ServerStorage["Pistol"],
	["WPN3"] = game.ServerStorage["SMG"],
}

local RankItems = {
	[150] = {"WPN1", "WPN2", "WPN3"},
	[160] = {"WPN1", "WPN2", "WPN3"},-- Team with 10 rank match
	[170] = {"WPN1", "WPN2", "WPN3"},
	[180] = {"WPN1", "WPN2", "WPN3"},
	[190] = {"WPN1", "WPN2", "WPN3"},
	[255] = {"WPN1", "WPN2", "WPN3"},
	
}

game.Players.PlayerAdded:Connect(function(Player)
	local GroupRank = Player:GetRankInGroup(GrpId)
	if Player.Team == game.Teams.Team then  -- Already changed.
	elseif RankItems[GroupRank] then
		for _, item in pairs(RankItems[GroupRank]) do
			item:Clone().Parent = Player.Backpack
			item:Clone().Parent = Player.StarterGear
		end
	end
end)

This’ll probably only work for your group items since your team can change

3 Likes

Doesn’t work for me, both ones.

1 Like

Try this out and tell me if it manages to print anything

local Players = game:GetService("Players")
local GrpId = 0-- Already changed

local Items = {
	["WPN1"] = game.ServerStorage["AR"],
	["WPN2"] = game.ServerStorage["Pistol"],
	["WPN3"] = game.ServerStorage["SMG"],
}

local RankItems = {
	[150] = {"WPN1", "WPN2", "WPN3"},
	[160] = {"WPN1", "WPN2", "WPN3"},-- Team with 10 rank match
	[170] = {"WPN1", "WPN2", "WPN3"},
	[180] = {"WPN1", "WPN2", "WPN3"},
	[190] = {"WPN1", "WPN2", "WPN3"},
	[255] = {"WPN1", "WPN2", "WPN3"},
	
}

game.Players.PlayerAdded:Connect(function(Player)
	local GroupRank = Player:GetRankInGroup(GrpId)
	if Player.Team == game.Teams.Team then  -- Already changed.
	elseif RankItems[GroupRank] then
		for _, item in pairs(RankItems[GroupRank]) do
			print(item)
			Items[item]:Clone().Parent = Player.Backpack
			Items[item]:Clone().Parent = Player.StarterGear
		end
	end
end)

Also it could be that first if statement

2 Likes

Nope nothing so fAr, and nothing in the output.

1 Like

Okay try this

local Players = game:GetService("Players")
local GrpId = 0-- Already changed

local Items = {
	["WPN1"] = game.ServerStorage["AR"],
	["WPN2"] = game.ServerStorage["Pistol"],
	["WPN3"] = game.ServerStorage["SMG"],
}

local RankItems = {
	[150] = {"WPN1", "WPN2", "WPN3"},
	[160] = {"WPN1", "WPN2", "WPN3"},-- Team with 10 rank match
	[170] = {"WPN1", "WPN2", "WPN3"},
	[180] = {"WPN1", "WPN2", "WPN3"},
	[190] = {"WPN1", "WPN2", "WPN3"},
	[255] = {"WPN1", "WPN2", "WPN3"},
	
}

game.Players.PlayerAdded:Connect(function(Player)
	local GroupRank = Player:GetRankInGroup(GrpId)
	print(GroupRank)
	local groupItems = RankItems[GroupRank]
	if groupItems then
		for _, item in pairs(groupItems) do
			print(item)
			Items[item]:Clone().Parent = Player.Backpack
			Items[item]:Clone().Parent = Player.StarterGear
		end
	end
end)

If it doesn’t work, what type of scritp is this and where is it located?

2 Likes

Your code is very messy and has a lot of unnecessary things in it.
Normally I’m not the type to spoonfeed people however I have the idea you’re not very experienced on the DevForum nor scripting in general so I rewrote your code.

local groupID = 0
local requiredRank = 0
local requiredTeam = game.Teams.YourTeamNameHere
local requiredTeam2 = game.Teams.YourTeamNameHere2

local function giveItem(player, item)
 if game.Players:FindFirstChild(player.Name) then
   local clonedItem = item:Clone()
   clonedItem.Parent = player.Backpack
    print("Successfully given: "..item.Name.." to "..player.Name)
   end
end

game.Players.PlayerAdded:Connect(function(plr)
 if plr:GetRankInGroup(groupID) >= requiredRank then
   if plr.Team == requiredTeam then
      giveItem(plr, game.ServerStorage.SMG)
    elseif plr.Team == requiredTeam2 then
      giveItem(plr, game.ServerStorage.AK12)
   end
  end
end)

Notes:

  • Hasn’t been tested
  • Wrote this here on the DevForum, might’ve forgotten a “end” here or there
  • To get other teams added, add a new local variable and call it something different. Then copy the line;
elseif plr.Team == teamVariableHere! then
      giveItem(plr, game.ServerStorage.ItemHere!)

and paste it directly under (before the end)

elseif plr.Team == requiredTeam2 then
      giveItem(plr, game.ServerStorage.AK12)
  • If you want to give a team ALL items in ServerStorage you simply can loop through the items in ServerStorage with a in pairs loop, check if it’s a tool and clone it into their backpack.

If you need more help feel free to let me know.

2 Likes

The script is located on serverscript service, and its a server script. Also, where do i put the team requiered to recieve the tools, like cops recieves each level a new tool, recruit no tools cop recieves gun / taser / etc. But that was the initial script and now i wanted it to be team only, since like sometimes cops teams into civilians and it get the tools from the cops and sometimes its abused.

1 Like

You can probably make a table of teams and the guns they receive liek how you did it for the Group Ranks. It should work if you do it like that, and you cna still probably keep the Group Rank checker

1 Like

I’d suggest just creating separate teams, and putting the tools in as their starter tools. Then the script would be about checking their group rank and assigning them to a group on join.

1 Like

Hey, did you manage to get it solved? If so, did it get solved through one of these posts? Make sure to mark the solution so others with the same problem can find the solution!

Hey Embat, you mind making script to give a player a weapon if they have a required group rank and on a specific team. I’ve been trying to but it constantly breaks on me every time.

Hey,

Could I use your code for my game?

I need it, but I don’t know how to make it, so I haven’t tried anything yet, I couldn’t find a good tutorial on YouTube.

I like to hear from you!

Edit: Kan ik Nederlands tegen je spreken, in plaats van Engels?

Goodbye,
Wilmer

Sure. Be my guest.

Try to learn how to script in the future yourself though, that allows you to understand stuff like this and write your own. It’s way more efficient than living on tutorials and “free” code snippets in the long term.

1 Like

Great, thanks for the code and the tip!