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

How do I change all of the Player's team at a certain time?

I have looked through this website searching for many ideas and answers but I can't understand any of them. (As you can tell I am pretty new to the coding scene)

local player = game.Players.LocalPlayer -- one of my problems is trying to locate all of the 
-- players in the game and moving them to a certain team.

ms = Instance.new("Message",workspace)
ms.Text = "Welcome to my testing place!"
wait(5)
ms:remove()
ms = Instance.new("Message",workspace)
ms.Text = "In five seconds you will be killed and changed to red team."
wait(5)
ms:remove()
ms = Instance.new("Message",workspace)
ms.Text = "You have changed ur team noob L!!!1!11!"
player.TeamColor = BrickColor.new('Bright red') -- as you can see I am completely lost.
wait(5)
ms:remove()

1 answer

✓ Accepted answer

GENERAL PRACTICE

Messages are considered deprecated, so you should be making a Gui with a Remote Event and Text Label, however, the below will still work.

Make "ms" into a local variable and change its text instead of destroying it.

Set the parent of the message outside of its Instance.new() function

ISSUES

This change is only occurring on the client, if you want to change the Player Teams, use the function on the Server.

In order to get all players, you can use the :GetPlayers() method to retrieve a table of players in the game and subsequently change their TeamColor.

REVISED SERVER SCRIPT

local ms = Instance.new("Message")
ms.Text = "Welcome to my testing place!"
ms.Parent = workspace
wait(5)
ms.Text = "In five seconds you will be killed and changed to red team."
wait(5)
ms.Text = "You have changed ur team noob L!!!1!11!"
for index, player in pairs(game:GetService("Players"):GetPlayers()) do
	player.TeamColor = BrickColor.new("Bright red")
end
wait(5)
ms:Destroy()

Due to FilteringEnabled, all changes on the Client will not be replicated to other players, which is why you shouldn't use a LocalScript Variant for this.

2 comments

0

Wow dude, thanks! I will try to get better at this.

0

You set the parent before changing properties yet talk about the parent parameter of Instance.new being bad lol, maybe actually read into what makes it bad in the first place before commenting about it

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