I am trying to make it so that when a player enters an area they switch teams.
I’m not sure if the best option for my game is by adding invisible non collide parts to each area and then making it so that when it is touched the player switches team.
I have already tried this and searched for quite a few tutorials but none of them have worked for me. Any tutorials etc will be much appreciated.
Put a script into the part that changes their team.
Paste this inside:
--//Services
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
--//Variables
local Part = script.Parent
--//Controls
local Team = Teams:WaitForChild("MyCoolTeamName")
--//Functions
Part.Touched:Connect(function(hit)
local Player = Players:GetPlayerFromCharacter(hit.Parent)
--//Checks if there is a player
if Player then
--//Sets the player's team
Player.Team = Team
end
end)
This works for me, so if any errors appear please tell me.
This won’t work for my game disappointingly. This is because of the map. When you move to a different area you don’t spawn in it you just walk into it.
Error: Room is not a valid member of Player “Players.cobaysaurus_rex” - Server - Script:20
The same error keeps happening in every video I watch. cobaysaurus_rex is my username just so you know.
--//Services
local Players = game:GetService("Players")
local Rooms = game:GetService("Teams")
--//Variables
local TheatreHitbox = script.Parent
--//Controls
local Room = Rooms:WaitForChild("Lobby")
--//Functions
TheatreHitbox.Touched:Connect(function(hit)
local Player = Players:GetPlayerFromCharacter(hit.Parent)
--//Checks if there is a player
if Player then
--//Sets the player's team
Player.Room = game.Rooms.Theatre
end
end)
Thank you so much for helping me. I figured out what was wrong with my script, which is that Players.Room should have been kept as Players.Team. It works like a charm!!! I always learn quite a bit from these experiences.