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

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

Asked by 5 years ago

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!

0
I forgot to mention that this script is inside of StarterCharacterScripts, inside of StarterPlayer. cooldeath49 37 — 5y
0
Theres nothing wrong with using the scripts from the toolbox. In fact, you should be using them. Why reinvent the wheel? User#24403 69 — 5y
1
Lol, good point. cooldeath49 37 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

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)

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? cooldeath49 37 — 5y
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 SerpentineKing 3885 — 5y
0
Ohhhhhhhhhhh, because I ran the command to change teams through the command line in Roblox Studio. Is that the problem? cooldeath49 37 — 5y
0
try testing the script in studio's test play, instead of through the command bar SerpentineKing 3885 — 5y
Ad

Answer this question