So, I have been trying to make it work, but it didn't work. This is my code below. Basically, I have a part when the player touches the part. The script inside the part where they change the player's team. It didn't work.
local part = script.Parent part.Touched:Connect(function(hit) if hit.Parent then local human = hit.Parent:FindFirstChild("Humanoid") if human then print("Changed Player's Team") SetTeam(human,"LevelTwo") end end end) function SetTeam(player, teamName) player.TeamColor = game.Teams[teamName].TeamColor if player.Character then player.Character:BreakJoints() end end
Well, a player object has a property called team, which can be assigned instead of assigning a team color . One thing you did wrong in your code is that you tried to set the team of the Player's humanoid to that team, not the actual player itself.
With that said
Here is the fixed code(revamped version)
local part = script.Parent part.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then print("Changed Player's Team") player.Team = game.Teams.LevelTwo hit.Parent:BreakJoints() end end)
In this answer, I used the GetPlayerFromCharcter
function of the players service, which returns a player when given a character, or it returns nil if the character parameter isn't a character.
game.Players:GetPlayerFromCharacter(instance Character)
Note that the Team property does not replicate across the client-server boundary, therefore it cannot be used in local scripts