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

How do I remove and give a gear automatically when you join a team?

Asked by 4 years ago

I'm trying to get the player get all their past tools removed and given new ones instantly after they switch teams, I don't know where to start with writing this script so any help is appreciated!

2 answers

Log in to vote
0
Answered by 4 years ago

Step 1.) Place tools inside Teams

Example: https://gyazo.com/910e954de4808da0f2bf1ff7e6987f75

Step2.) Place a script into ServerScriptService

paste this code into it.

01function teamFromColor(color)
02for _,t in pairs(game:GetService("Teams"):GetChildren()) do
03if t.TeamColor==color then return t end
04end
05return nil
06end
07 
08function onSpawned(plr)
09local tools = teamFromColor(plr.TeamColor):GetChildren()
10for _,c in pairs(tools) do
11c:Clone().Parent = plr.Backpack
12end
13end
14 
15function onChanged(prop,plr)
View all 27 lines...

I hope this helped!

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Create a Folder Inside of ServerStorage, Call it "Tools".

Create a Folder for every team inside of the first, name each the team's name and put the team's tools inside it.

Put this script in ServerScriptService:

01local ServerStorage = game:GetService("ServerStorage")
02local Teams = game:GetService("Teams")
03local Tools = ServerStorage:FindFirstChild("Tools")
04 
05function ClearTools(Backpack,StarterGear)
06    for i,v in ipairs(Backpack:GetChildren()) do
07        if v:IsA("Tool") then
08            v:Destroy()
09        end
10    end
11    for i,v in ipairs(StarterGear:GetChildren()) do
12        if v:IsA("Tool") then
13            v:Destroy()
14        end
15    end
View all 39 lines...

Tools reset each time player changes teams

Answer this question