Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change teams via on-screen buttons ?

Now I wish to be able to change teams by clicking on a button on a screen (Just like Jailbreak). The script is a LocalScript And I've come up with this so far:

local Button = script.Parent
local Team = game.Teams
local Player = game.Players.LocalPlayer

function OnClicked(Teams)
	Player.Team = "Astronauts"
end

Button.MouseButton1Down:connect(OnClicked)

1 answer

✓ 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

0

Thank you, but what do I need to add if I want the player to reset after changing team ?

0

player.Humanoid.Health = 0

0

I've edited the code in the script. Use that.

This discussion is preserved as it was. New answers, comments, and votes are closed.