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

I'm having problems with team changing, anything to help?

Hi scripters, I've made a small section of code that is expected to change a player's team when they die. I don't feel like using the pre-coded scripts that are available for purchase from the Library, since i want to figure this out myself. The problem is, when the Humanoid dies in my script, a few moments later the player changes team to Neutral, but instead it creates a new team called Neutral. Any advice?

local Character = script.Parent
local Humanoid = Character.Humanoid
local Player = Character.Name
local FoundPlayer = game.Players:WaitForChild(Player)
local Neutral = game.Teams.Neutral

Humanoid.Died:connect(function()
		FoundPlayer.Team = Neutral
end)

Advice is appreciated!

3 comments

0

I forgot to mention that this script is inside of StarterCharacterScripts, inside of StarterPlayer.

0

Theres nothing wrong with using the scripts from the toolbox. In fact, you should be using them. Why reinvent the wheel?

1

Lol, good point.

1 answer

Assuming this is a Server Script,

Please make sure that you have Two Teams in the game.Teams Folder before you start the game (the obvious exception being that the team is added while in-game --- if this is the case, please comment below and I will be happy to assist you with that)

One of these two Teams should be named "Neutral" and have its AutoAssignable Property set to false, while the other Team (the name doesn't matter for this script) should have its AutoAssignable Property set to true.

Upon testing, I found nothing wrong with your script's code, however, I suggest capitalizing "connect" to "Connect" as the lowercase is considered deprecated (although it will work at times)

4 comments

0

Sorry for bugging you. The first time the player died, the team swap occured correctly. However, when I switch teams again, and then die, it does not work. Is there a solution to this?

0

did you switch teams on the Client or the Server? If you switched on the Client only, it would not replicated to the Server, and thus the Server would think you are still on the "Neutral" team

0

Ohhhhhhhhhhh, because I ran the command to change teams through the command line in Roblox Studio. Is that the problem?

0

try testing the script in studio's test play, instead of through the command bar

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