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

Group Only Spawn script isn't working properly?

I have a Group Only spawn script that seems like it would work properly, but whenever someone clicks it, it makes a Neutral team and teams them to Neutral. To my understanding, I am doing everything right. Can somebody tell me what is wrong with it?

group = 2964900
deb = true


script.Parent.Touched:connect(function(p)
if p ~= nil then 
deb = false 
local human = p.Parent
if human ~= nil then
local player = game.Players:GetPlayerFromCharacter(human)
if player ~= nil then
if player:IsInGroup(group) then
player.TeamColor = BrickColor.new("Navy Blue")
end
end
end
end
end)


3 comments

0

I believe you have to add the team as well?

0

What do you mean?

1

Do you already have a "Navy Blue" team placed in "Teams"? Also, the color is called, "Navy blue", without the capital B. Gotta be exact with those things.

1 answer

From what I can tell, you're trying to assign the team by changing the team color property inside the player.

However, you'll want to assign a player to a team using the team instance in the Teams service. Take this short script, for example, it'll assign every player in the game to a certain team.

local team = Instance.new("Team")
team.TeamColor = BrickColor.random()
team.Parent = game:GetService("Teams")
 
for _, player in pairs(game:GetService("Players"):GetPlayers()) do
    player.Team = team -- Notice the variable team is being assigned to player.Team and not player.TeamColor
end

So using our newly found knowledge. Let's see if we can get your script working correctly.

group = 2964900
deb = true


script.Parent.Touched:connect(function(p)
	if p ~= nil then 
		deb = false 
		local human = p.Parent
		if human ~= nil then
			local player = game.Players:GetPlayerFromCharacter(human)
			if player ~= nil then
				if player:IsInGroup(group) then
					player.Team = game:GetService("Teams"):FindFirstChild("Team Name") --the player will now change to the team named "Team Name"
				end
			end
		end
	end
end)

Once the player's team is switched, the team color property in the player instance will adjust to the correct color. Source

1 comment

0

It doesn't work, everybody can join the team when I have this inserted. It goes in the team spawn pad, correct?

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