As before, I am making a game involving Team Change.
When I made a GUI with a script telling it to make a GUI visible, when I told it to change the players teams, the script crashed.
Variables(for Team Change):
local Player = game.Players.LocalPlayer local Citizen = game.Players.LocalPlayer:FindFirstChild("Team"):FindFirstChild("Citizen")
for the Visible part:
local Confirm = game.Players.LocalPlayer:FindFirstChild("PlayerGui"):FindFirstChild("Team Selector").Confirmation
The function:
script.Parent.MouseButton1Click:connect(function() Confirm.Visible = true Player.Team = Citizen end)
Put Together:
local Confirm = game.Players.LocalPlayer:FindFirstChild("PlayerGui"):FindFirstChild("Team Selector").Confirmation local Player = game.Players.LocalPlayer local Citizen = game.Players.LocalPlayer:FindFirstChild("Team"):FindFirstChild("Citizen") script.Parent.MouseButton1Click:connect(function() Confirm.Visible = true Player.Team = Citizen end)
When run, Like I said, It all crashes. What do I have to do?
There may be some confusion, but it is okay to change TeamColor or Team property when assigning a player to a team. However, by changing the Team property, you must give the actual Instance of the Team and Team must be a part of the Team Service before either changes!
Looking at your code, local Citizen = game.Players.LocalPlayer:FindFirstChild("Team"):FindFirstChild("Citizen")
seems strange. You should find a team named Citizen by looking through the TeamService. And again, keep in mind if you attempt to change TeamColor to a non-existent team's color, the player will be put in neutral or you get an error, depending on what you're doing.
See below on a script that should work, although I am unsure if changing team through localscripts will work, you may need to use Remotes to change the team. On the note of your crashes, I see nothing that should result in one, it may be a difference script you are not showing us.
local Confirm = game.Players.LocalPlayer:FindFirstChild("PlayerGui"):FindFirstChild("Team Selector").Confirmation -- unsure why you don't use FindFirstChild for Confirmation local Player = game.Players.LocalPlayer local Citizen =game:GetService("Teams"):FindFirstChild("Citizen") script.Parent.MouseButton1Click:Connect(function() -- Connect should be capitalized, changes nothing but is desired Confirm.Visible = true Player.Team = Citizen end)
When you change the Team, you want to change the player's TeamColor. Look here and here! Not the team itself.
EXAMPLE (NOT BY ME):
function setTeam(player, teamName) player.TeamColor = game.Teams[teamName].TeamColor if player.Character then --Just in case the character doesn't exist for some reason player.Character:BreakJoints() -- Kills the players' character end end --How it's used setTeam(game.Players.anth4598, "Blues") --Changing everyone's team to "Reds" for _, player in pairs(game.Players:GetPlayers()) do setTeam(player, "Reds") end