Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I change this to a team tool giver?

How would I make it so instead of giving a tool to a specific player, it gives it to a specific team instead?

game.Players.PlayerAdded:Connect(function(player)
 player.CharacterAdded:connect(function(character)
  if player.Name == "Username" then
   for _,v in pairs (game.ServerStorage.Tools:GetChildren()) do
    v:Clone().Parent = player.Backpack
   end
  end
 end)
end)

2 comments

0

Are there multiple tools that you want to give the players?

0

yes

1 answer

✓ Accepted answer

This should assign the proper tools to respective teams. Ensure the ServerStorage folder that houses the tools has them sorted into separate child folders matching the team names. E.g:


ServerStorage

"Tools" - Folder

    "Assassins" - Folder

        - Tool Instances

     Etcetera...

--###----------[[SERVICES]]----------###--
local ServerStorage = game:GetService("ServerStorage")

local Players = game:GetService("Players")


local Teams = game:GetService("Teams")



--###----------[[VARIABLES]]----------###--
local ToolSet = ServerStorage.Tools



--###----------[[FUNCTIONS]]----------###--
local function TransferTeamTools(Player)
        local Backpack = Player.Backpack
        ---------------
        local TeamTools = ToolSet:FindFirstChild(Player.Team.Name)
        if (TeamTools) then
            ---------------
            Backpack:ClearAllChildren()
            ---------------
            for _, Tool in pairs(TeamTools) do
                ---------------
                Tool:Clone().Parent = Backpack
            end
        end
    end
end



--###----------[[SETUP]]----------###--
Players.PlayerAdded:Connect(function(Player)
    ---------------
    Player:GetPropertyChangedSignal("Team"):Connect(TransferTeamTools)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.