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

How Do I Change The TeamColor Of A Player?

Asked by 6 years ago

Hi guys please help me out, because I don't know and I've been trying random things but they don't work... place is not FE.

game.Players.PlayerAdded:Connect(function(plyr)

script.Parent.MouseButton1Down:Connect(function()

plyr.TeamColor = BrickColor.new("Pastel Blue")

end)

end)

ive done things like making the neutral thing off i just dont know anymore pls help

0
I want the player to switch teams when they press the textbutton from neutral to the other team dareveloper 9 — 6y

1 answer

Log in to vote
1
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

You're listening for game.Players.PlayerAdded, which is an event that fires when a player joins. This isn't quite what you want, but it's great that you tried to solve this problem yourself before asking.

We can use the Player.Team rather than the Player.TeamColor property to make our code clearer.

We need two scripts. One, server-side, should handle requests from the client (player's computer) to change teams. It should check if the team requested is one that can be switched to, and if so, switch the player's team. The client-side code should listen for button presses and fire the server when pressed.

Server-side Script code in game.ServerScriptService:

local TeamsService = game:GetService("Teams")

local TeamSwitch = game.ReplicatedStorage.Network.TeamSwitch

TeamSwitch.OnServerEvent:Connect(function(Player, Team)
    if typeof(Team) ~= "instance" then
        return
    end

    if not Team:IsA("Team") or Team.Parent ~= TeamsService then
        return
    end

    Player.Team = Team
end)

Client-side LocalScript code in the GUI button (I recommend moving this to game.StarterPlayer.StarterPlayerScripts, as scripts really don't belong in GUI objects):

local TeamsService = game:GetService("Teams")

local LocalPlayer = game.Players.LocalPlayer

local TeamSwitch = game.ReplicatedStorage.Network.TeamSwitch

local Button = script.Parent

Button.MouseButton1Click:Connect(function()
    local TeamSwitchTarget = nil
    -- We could use the and / or operators here if we wanted to.
    if LocalPlayer.Team == TeamsService.Red then
        TeamSwitchTarget = TeamsService.Blue
    else
        TeamSwitchTarget = TeamsService.Red
    end

    TeamSwitch:FireServer(TeamSwitchTarget)
end)

Note that Network is a folder, and TeamSwitch is a RemoteEvent.

0
if a team called white walkers and people normally spawn on neutral team how would u make it like that LuckiestJade -5 — 6y
0
If you only want their team set once they press the button, modify my client-side code to do just that inside the button event listener. However, if there are other teams that you do not want players to be able to switch to, I would change my server-side RemoteEvent handling to check for this. Avigant 2374 — 6y
Ad

Answer this question