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

Team Change Script Not Working. What happend?

Asked by
Zikelah 20
4 years ago
Edited 4 years ago

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?

2 answers

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

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)
0
If there are issues, feel free to comment below! I believe this would work theoretically but again, a RemoteEvent may be needed alphawolvess 1784 — 4y
0
Thanks. This is the current script Zikelah 20 — 4y
1
THANK YOU SO MUCH! It worked Perfectly. Zikelah 20 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Source

0
??????????????? Zikelah 20 — 4y
1
Inside of the roblox wiki, and I quote "Changing Player.TeamColor will cause Player.Team to switch to the Team with the corresponding Team.TeamColor" so as BennyBoiOriginal said, just change the TeamColor property of team. beeswithstingerss 41 — 4y

Answer this question