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

How to change teams via on-screen buttons ?

Asked by 6 years ago

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

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
Thank you, but what do I need to add if I want the player to reset after changing team ? LordTechet 53 — 6y
0
player.Humanoid.Health = 0 DaWarTekWizard 169 — 6y
0
I've edited the code in the script. Use that. UgOsMiLy 1074 — 6y
Ad

Answer this question