✓ Accepted answer
Edit: I have edited the script below to reset the player after changing teams
You would use Remote Events, not because changing teams isn't simple, it is; but with FIlteringEnabled, if you change your team on a Local Script you will see yourself on the Astronauts team but other players won't, and that will cause confusion within your game. A server script will work, but this can't be handled with just a server script, as they won't work inside a player, and they can't access the PlayerGui.
So, you would use both.
Put a RemoteEvent inside ReplicatedStorage named ChangeTeam
Make sure there is a Team inside the Teams folder named Astronauts
In your LocalScript
local Button = script.Parent
local Teams = game:GetService("Teams")
local event = game:GetService("ReplicatedStorage"):WaitForChild("ChangeTeam")
local Player = game.Players.LocalPlayer
function OnClicked()
event:FireServer(Teams:WaitForChild("Astronauts"))
end
Button.MouseButton1Down:Connect(OnClicked)
In a Script in the ServerScriptService
local event = game:GetService("ReplicatedStorage"):WaitForChild("ChangeTeam")
event.OnServerEvent:Connect(function(player,team)
player.Team = team
if player and player.Character then
player.Character:BreakJoints()
end
end)
3 comments
Thank you, but what do I need to add if I want the player to reset after changing team ?
player.Humanoid.Health = 0
I've edited the code in the script. Use that.