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

Why does my group auto assign script not work?

I've been making a game for a group and I'm having issues with an auto assign script. This is my code:

game.Players.PlayerAdded:connect(function(player) 
    if player:GetRankInGroup(5418984) > 0 then 
        player.Team = "Officers"  
    else 
        player.Team = "Raiders" 
end
end)

I'm generally new to coding, so help would be appreciated! Also, I get no errors when I run this.

1 comment

0

Wait, my script, yeah, it have a problem :P ,edited.

2 answers

Ok, before we start, I'll say what's wrong in your's script.

Simply that GetRankInGroup() is not working, try to use IsInGroup() instead, because GetRankInGroup() is just give peoples get rank in the group, that you can use this to make a changing rank bot.

The working script is like this.

function onPlayerEntered(player)
	if player:IsInGroup(2621202) then  -- Change the number in brackets to your GroupID
		player.TeamColor = BrickColor.new("Bright Green") -- change the Bright Green become the Officer's TeamColor
	else 
		player.TeamColor = BrickColor.new("New Yeller") -- change the New Yeller become the Raiders TeamColor
	end
end

game.Players.PlayerAdded:connect(onPlayerEntered)

If you have more questions, or need some more explanation, ask below! I'll be glad to help ;D

4 comments

0

PM me if you have other questions! :)

0

Thanks for the response! Although, this just puts my team as Neutral. I also already have teams called Officers and Raiders, so do I need to remove them or something?

0

Wait, my script, yeah, it have a problem :P ,edited.

0

I think I'm doing something wrong... I changed it as you said, my colors are Deep blue and Really red, yet now I don't even get teamed at all. Not even neutral. My teams are in the Teams folder, do I move them?

The problem isn't the group check (even though you should be using Player:IsInGroup()), it's the way you set the player's team. From the wiki page on Player.Team :

The Team property is a reference to a Team object within the Teams service.

So instead of player.Team = "teamName", you should use player.Team = game.Teams.teamName:

game.Players.PlayerAdded:connect(function(player) 
    if player:IsInGroup(5418984) then 
        player.Team = game.Teams.Officers  
    else 
        player.Team = game.Teams.Raiders 
    end
end)

1 comment

0

Thank you! This worked.

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