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

I'm not sure how to change the players team?

Asked by 1 year ago

A very simple question, almost the entirety of the two scripts are working but I'm not sure what I am supposed to do to change the players team, a local script in an ImageButton is triggering a RemoveEvent containing the players name and team they want to change to, this all works just fine, but I can't figure out how to then change the player to the team that is taken from the RemoveEvent as "Button".

Local GUI script:

local Button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("ChangeTeam")

Button.MouseEnter:Connect(function()

    print("Entered")
    Button.ImageColor3 = Color3.new(255, 255, 255)

end)

Button.MouseLeave:Connect(function()

    print("Left")
    Button.ImageColor3 = Color3.new(0.72549, 0.72549, 0.72549)

end)

local function onButtonActivated()
    print("Button activated!")

    RemoteEvent:FireServer(Button)

end

Button.Activated:Connect(onButtonActivated)

ServerScriptService script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:FindFirstChild("ChangeTeam")
local Teams = game:GetService("Teams")

local function Change(player, Button)

    print(Button)
    print(player)

    player.Team = -- Not sure what is supposed to go here to change the player to the required team

end

RemoteEvent.OnServerEvent:Connect(Change)

Could someone tell me what to put on the 3rd last line? Thanks!

1 answer

Log in to vote
0
Answered by 1 year ago

Firstly, there's no need to replicate the GUI Button. Player.Team is an object property so set it to an existing Team Object. If you've already made a team in game.Teams then you could assign Player's team to that team.

Ad

Answer this question