Hi there,
In this tutorial, I’ll be teaching you how we can use Teams
to make Only Team..
Examples:
Only Certain team Door
, Only Certain team tools
, etc…
Quick Introduction
Before we dive into it, lets understand what functions and events we’re going to meet with[ relevant to teams]:
Properties
AutoAssignable[boolean]
: if set to true, the player would be automatically able to join this team.
TeamColor]brickcolor]
: describes the color of the player’s team.
Unique Functions
GetPlayers()
: returns a table of all players on the given team.[Player’s Neutral property has to be false in order to take that player into consideration when using this function]
Events
PlayerAdded
: fires when a player is added to a team.[Player’s Neutral property has to be false in order to take that player into consideration when using this event]
PlayerRemoving
: fires when a player is removed from a team.[[Player’s Neutral property has to be false in order to take that player into consideration when using this event]
Getting Started
Alright guys, so after we’ve talked about these stuff,
lets now move onto some fresh examples!
Team Only Door:
Make sure you have a door infront of you , and make sure it has a main part to work with.
--//Variables
local Teams = game:GetService("Teams")
local Allowed_Team = Teams:FindFirstChild("Blue")
local Door = script.Parent
local CD = Door:FindFirstChild("ClickDetector")
local Delay = 3
--//Functions
local function CheckTeam(Player)
--if our player's team is not on the 'Allowed_Team' then we kill him
if Player.Team ~= Allowed_Team then
Player.Character:WaitForChild("Humanoid").Health = 0
end
--if he is on the 'Allowed_Team' then we will let him get through
Door.CanCollide = false
task.wait(Delay)
Door.CanCollide = true
end
--//Logic--calling the function
CD.MouseClick:Connect(CheckTeam)
Team Only Gears
Make sure you have a folder called ‘Gears’ in each team you have.
--//Variables
local Teams = game:GetService("Teams")
local Players = game:GetService("Players")
local List = Teams:GetTeams() -- returns a table containing all the current teams in 'Teams' service
--//Functions
local function CheckTeam(Player)
--If our player is on Neutral or not on a team then we stop the function
if Player.Neutral == true or Player.Team == nil then return end
--Else
for _,Team in pairs(List) do
--If the player's team is indeed on the list
if Player.Team == Team then
return Team -- meaning, we'll be able to access it and do stuff later on
end
end
end
local function OnTeamChange(Player)
--If the team he's changing into isn't on the teams list, then we stop the function
if Player.Team == nil or Teams:FindFirstChild(Player.Team.Name) == nil then return end
--Here,we're looking for the team he's changed into, and giving him his stuff.
local IsRealTeam = Teams:FindFirstChild(Player.Team.Name)
--Only if his team is indeed inside Teams Service then..
if IsRealTeam then
local Gears = IsRealTeam:FindFirstChild("Gears"):GetChildren()
for _,Gear in pairs(Gears) do
local Clone = Gear:Clone()
Clone.Parent = Player.Backpack
end
end
end
local function PlayerAdded(Player)
--Detecting when the player's Team[Object Value] changes ,and we call the 'OnTeamChange' function inside
Player:GetPropertyChangedSignal("Team"):Connect(function()
OnTeamChange(Player)
end)
Player.CharacterAdded:Connect(function(Character)
--Since we returned 'Team', that means, this part:"CheckTeam(Player)" is the player's team.
--We then access into the 'Gears' folder and get every gear we have there.
local Team_Tools = CheckTeam(Player):FindFirstChild("Gears"):GetChildren()
for _,Tool in pairs(Team_Tools) do
local clone = Tool:Clone()
clone.Parent = Player.Backpack
end
end)
end
--//Logic
Players.PlayerAdded:Connect(PlayerAdded)
Team Only Teleporter
Make sure you have a teleport [ brick/portal, etc…] but make sure to have a main part to teleport the player through.
--//Variables
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local Allowed_Team = Teams:FindFirstChild("Red")
local list = Teams:GetTeams()
local Portal = script.Parent
local Destination = CFrame.new(0,5,0) -- Where to teleport the player
local Debounce = false
local Delay = 3
--//Functions
local function TeamCheck(Player)
--If the player is neutral or his team doesnt appear on our team list then we stop the function
if Player.Neutral == true or Player.Team == nil then return end
--Else
if Player.Team == Allowed_Team then
return true
end
end
local function TeleportPlayer(Player:Model,Destination:CFrame)
Player:PivotTo(Destination)
end
local function OnTouchedPart(Object)
local isModel = Object:FindFirstAncestorWhichIsA("Model")
local isHumanoid = isModel:FindFirstChildWhichIsA("Humanoid")
local realPlayer = Players:GetPlayerFromCharacter(isModel)
local Team_Check = TeamCheck(realPlayer)
--If the object is a descendant/child of a model, which has humanoid inside, we'll check if it is a player
if isHumanoid then
if Team_Check then
if Debounce == false then
Debounce = true
--Teleporting the player
TeleportPlayer(isModel,Destination)
task.wait(Delay)
Debounce = false
end
end
end
end
--//Logic
Portal.Touched:Connect(OnTouchedPart)
Team Only Gui
If you want that UI to not disappear when dieing, then simple set ResetOnSpawn
to false
--//Variables
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local Allowed_Team = Teams:FindFirstChild("Blue")
local list = Teams:GetTeams()
--//Functions
local function TeamCheck(Player)
--If the player is neutral or his team doesnt appear on our team list then we stop the function
if Player.Neutral == true or Player.Team == nil then return end
--Else
if Player.Team == Allowed_Team then
local GUI = script.Blue:Clone()
local PlayerGui = Player:WaitForChild("PlayerGui")
if PlayerGui then
GUI.Parent = PlayerGui
end
end
end
local function OnTeamChange(Player)
--If the player is neutral or his team doesnt appear on our team list then we stop the function
if Player.Neutral == true or Player.Team == nil then return end
--Else
if Player.Team == Allowed_Team then
local GUI = script.Blue:Clone()
local PlayerGui = Player:WaitForChild("PlayerGui")
if PlayerGui then
GUI.Parent = PlayerGui
end
else
--If he has that ui, destroy it.
local GUI = "Blue"
local PlayerGui = Player:WaitForChild("PlayerGui")
if PlayerGui and PlayerGui:FindFirstChild(GUI) then
PlayerGui:FindFirstChild(GUI):Destroy()
end
end
end
local function PlayerJoined(Player)
Player:GetPropertyChangedSignal("Team"):Connect(function()
OnTeamChange(Player)
end)
TeamCheck(Player)
end
--//Logic
Players.PlayerAdded:Connect(PlayerJoined)
Team Only Clothes
Make sure to have a folder named Clothing
inside each team you have.
--//Variables
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local list = Teams:GetTeams()
--//Functions
local function CheckTeam(Player)
--If our player is on Neutral or not on a team then we stop the function
if Player.Neutral == true or Player.Team == nil then return end
--Else
for _,Team in pairs(list) do
--If the player's team is indeed on the list
if Player.Team == Team then
return Team -- meaning, we'll be able to access it and do stuff later on
end
end
end
local function OnTeamChange(Player)
--If the team he's changing into isn't on the teams list, then we stop the function
if Player.Team == nil or Teams:FindFirstChild(Player.Team.Name) == nil then return end
--Here,we're looking for the team he's changed into, and giving him his stuff.
local IsRealTeam = Teams:FindFirstChild(Player.Team.Name)
--Only if his team is indeed inside Teams Service then..
if IsRealTeam then
local Clothing = IsRealTeam:FindFirstChild("Clothing")
--Shirt checking
if Player.Character:FindFirstChildWhichIsA("Shirt") then
Player.Character:FindFirstChildWhichIsA("Shirt").ShirtTemplate = Clothing:FindFirstChild("Shirt").ShirtTemplate
else
local newShirt = Instance.new("Shirt")
newShirt.Name = "Shirt"
newShirt.ShirtTemplate = Clothing:FindFirstChild("Shirt").ShirtTemplate
newShirt.Parent = Player.Character
end
--Pants checking
if Player.Character:FindFirstChildWhichIsA("Pants") then
Player.Character:FindFirstChildWhichIsA("Pants").PantsTemplate = Clothing:FindFirstChild("Pants").PantsTemplate
else
local newPants = Instance.new("Pants")
newPants.Name = "Pants"
newPants.PantsTemplate = Clothing:FindFirstChild("Pants").PantsTemplate
newPants.Parent = Player.Character
end
end
end
local function PlayerAdded(Player)
--Detecting when the player's Team[Object Value] changes ,and we call the 'OnTeamChange' function inside
Player:GetPropertyChangedSignal("Team"):Connect(function()
OnTeamChange(Player)
end)
Player.CharacterAdded:Connect(function(Character)
--Since we returned 'Team', that means, this part:"CheckTeam(Player)" is the player's team.
--We then access into the 'Clothing' folder and get every Clothing we have there.
local Team_Clothing = CheckTeam(Player):FindFirstChild("Clothing")
--Shirt checking
if Character:FindFirstChildWhichIsA("Shirt") then
Character:FindFirstChildWhichIsA("Shirt").ShirtTemplate = Team_Clothing:FindFirstChild("Shirt").ShirtTemplate
else
local newShirt = Instance.new("Shirt")
newShirt.Name = "Shirt"
newShirt.ShirtTemplate = Team_Clothing:FindFirstChild("Shirt").ShirtTemplate
newShirt.Parent = Character
end
--Pants checking
if Character:FindFirstChildWhichIsA("Pants") then
Character:FindFirstChildWhichIsA("Pants").PantsTemplate = Team_Clothing:FindFirstChild("Pants").PantsTemplate
else
local newPants = Instance.new("Pants")
newPants.Name = "Pants"
newPants.PantsTemplate = Team_Clothing:FindFirstChild("Pants").PantsTemplate
newPants.Parent = Character
end
end)
end
--//Logic
Players.PlayerAdded:Connect(PlayerAdded)
More coming soon
- I knew that already ,what a coincidence
- Thank you! Now I know how to…
0 voters