Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How Does This Team Only Tools Code Exactly Work To Give Teams Tools?

Asked by 2 years ago

Can someone break down this code for me so I know exactly what it does?

function teamFromColor(color)
    for _,teams in pairs(game:GetService("Teams"):GetChildren()) do
        if teams.TeamColor == color then return teams end
    end
    return nil
end

function Spawned(player)
    local tools = teamFromColor(player.TeamColor):GetChildren()
    for _,tools in pairs(tools) do 
        tools:Clone().Parent = player.Backpack
    end
end

function Adjusted(character,player)
    if character == "Character" then
        Spawned(player)
    end
end

function Joined(player)
    player.Changed:Connect(function(character)
        Adjusted(character, player)
    end)
end

game.Players.PlayerAdded:Connect(Joined)
0
btw where did you find this script? can you post the link here JesseSong 3916 — 2y
0
Also, I'd recommend using a different script, or an easier alternative (i.e. you could search for a different video). This script is pretty hard to understand for beginners, so I wouldn't recommend it! I recommend people like TheDevKing and Peaspod (Peasfactory) etc JesseSong 3916 — 2y

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

Essentially, what the script does is it gets the service of teams and all the children inside it. Then it checks to see if the teamcolor is equal to the color it wants (in other words, it checks the teamcolor with an if statement) and then returns the value (teams).

After that, the second function returns the first function in line 9. What I mean by this is that in line 9, where it says:

local tools = teamFromColor(player.TeamColor):GetChildren()

teamFromColor is the same function as in line 1. (or another word would be return)

Next, the 2 function gets all the people and clones all the tools, and places them in the character's backpack. The third function has an argument of character and player. The character argument checks to see if it's actually a character and then returns the items in the player's backpack. And lastly, the last function functions when a player enters the game, because there is a PlayerAddedevent:

game.Players.PlayerAdded:Connect(function(player) -- functions when a player enters the game

end)

Re - edited

function teamFromColor(color) -- just a simple function with a parameter of color
    for _,teams in pairs(game:GetService("Teams"):GetChildren()) do -- this loops through the service and gets all the players
        if teams.TeamColor == color then return teams end --checks the players team
    end
    return nil -- returns nothing
end

function Spawned(player) -- another function
    local tools = teamFromColor(player.TeamColor):GetChildren() -- checks the teamcolor
    for _,tools in pairs(tools) do  -- loops through the table
        tools:Clone().Parent = player.Backpack -- clones it and stores it in backpack
    end
end

function Adjusted(character,player)
    if character == "Character" then -- checks if its a character
        Spawned(player) -- calls the function
    end
end

function Joined(player)
    player.Changed:Connect(function(character) 
        Adjusted(character, player) -- calls the function to run
    end)
end

game.Players.PlayerAdded:Connect(Joined) -- functions when a player enters the game

This is pretty hard to explain, if you need me to break it down more, then ask.

0
alright i got the basic overview of it, thanks, if ive got any more questions about it later ill ask you SuperSM1 67 — 2y
Ad

Answer this question