I need some help with a Group Team Rank script

I have tried looking at Wiki pages to get more information on how to use it to change teams, along with youtube tutorials, but most of them look to be outdated and, don’t work for some reason.

Here’s the script that I put together from all of these resources.

function Click(mouse) 
    game.Players.PlayerAdded:Connect(function(player) 
     if player:GetRankInGroup(6392114) >= 1 then
         script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Smoky grey") 
      end
   end)

script.Parent.MouseButton1Click:Connect(Click)

It doesn’t work and all I get is some error message regarding end. I don’t get any error messages for anything else.

1 Like

Hey there Messeras,

Could I ask what this is?

script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Smoky grey") **strong text**

Shouldn’t you just do player.TeamColor = BrickColor.new(“Smoky grey”)?

Edit: Also, why do you have that inside a clickdetector function? If you have a click detector it wont fire inside a player.
Edit 2: Disregard the above, I am blind

1 Like

If you’re trying to change the team of the player based on their group rank, the player instance has a team property. I’m not sure why you’re doing script.Parent.Parent (and so on), but there is a much more simple way to accomplish this.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(6392114) >= 1 then
		Player.TeamColor = BrickColor.new("Smoky grey")
	end
end)

Also, as HiddenKaiser stated, you shouldn’t be hooking up a PlayerAdded event everytime that a MouseButton1Click event is fired. You should have the event be independent within a serverscript.

2 Likes

I forgot to specify, this is within a TextButton, sorry for the confusion!

Alright, a click detector will not work in a textbutton, as well as changing the team on the client will not do anything (the script must be client to detect clicks) . Look into remoteevents and the .MouseButton1Click event

1 Like

I’ve spotted 3 problems with your code.

  1. You are missing an end that should be connected to the Click function.
    putting “end” right after the other “end)” will fix this one.

  2. You’ve got the order of your functions mixed up:

  • On like 8 you create a listener for clicking.
  • After being clicked it creates a listener for Joining Players
    The player would have already joined the game before creating the listener.
  1. As @HiddenKaiser pointed out you aren’t able to change player teams from the client.

Extra note:

If this is a local script under a text button there is no need for a PlayerAdded function. You can also call player by game.Player.LocalPlayer.

1 Like

Sorry if I sound a bit rude!

I want to do this, but how would I make it on MouseButton1Click, that it checks if the player meets these standards, and then places them on the team. It’s because I don’t want some scripts overlapping others forcing the player into random teams.

Hey there,

I don’t want to be rude or anything but…
Even if he does this you can’t change the team on the client.

2 Likes

@OP, from everything the users have said in here, i suppose the issue is solved, please choose one of the replies as an/the solution.

1 Like

My mistake, thank you for reminding me I’ll adjust my post.

2 Likes

I hope this can help,

  1. Have a remote event in replicated storage (local remote = game.ReplicatedStorage.ChangeTeam)

  2. On your client hook remote:FireServer() into your click function.

  3. On the server (somewhere in server script service), check if their rank in the group and if so team them
    Ex: remote.OnServerEvent:Connect(function(player)
    – if player:GetRankInGroup blah blah blah
    if so then player.TeamColor = brickcolorhere

2 Likes

If you want to make it so they are assigned a team upon clicking a button, rather than when they join - you will need to use a RemoteEvent and fire to the server. For starters, you should scrap the PlayerAdded event if you are not going to be assigning teams based on when they join. This would not work in a localscript regardless.

If you want to make this work with a GUI button, I would fire to the server using a remoteevent, and have a listener on the server that waits on the client to request a team change. Inside the serverside listener, I would put all of this code:

if Player:GetRankInGroup(6392114) >= 1 then
	Player.TeamColor = BrickColor.new("Smoky grey")
end

You can use several elseif statements to continously figure out what team they are, and then assign them a team on the server. The first parameter of the serverside listener is the player that is firing to the client, so that is how you can access the player and set their team using the TeamColor property.

Hope this helped!

4 Likes

Sir, I have several questions. it will not replicate and you will run into some major issues. This is unless you’re writing in a gui serverscript in which case you’re not even writing in filtering enabled.

3 Likes

I actually used an localscript? Could you tell me some of the issues?

Post was unrelated sorry,

I’ll explain in this next edit

So, what happens when you only change on client is that only the player you changed it on see’s the changes, usually this gives you issues with spawnlocations and the like.
I see @straphos has finished answering the rest.

3 Likes

Changing teams from the client will not replicate to the server. In other words, the server will not see that you are on that team, and any actions on the server will not apply to you since you are not on it.

If changing teams replicated to the server from the client, exploiters would be able to go on any team that they want with no problem. This, however, is not the case.

4 Likes

This is a lot of information for me to process as a new scripter, so basically (want to make sure I got this right), I have to put a RemoteEvent somewhere, and when the player clicks on the gui, it sends a request to the remote event and it checks if the player is in the group and has the right rank.
It then will place the player in the team, if everything checks out.

Where do I put the RemoteEvent and how do I make it send the request to the RemoteEvent?
Still very new to scripting, and I’ve been trying to learn from wiki pages and tutorials.

1 Like

I went over it here, although it’s pretty messy.

I would recommend putting the RemoteEvent in ReplicatedStorage since you’ll want both the client and server to be able to reference it. Once you define the event, you will need to fire to the server once the button is clicked. This is how it will look on the client assuming that you are not passing along any arguments:

TeamEvent:FireServer()

On the server, you will have a listener for this event. It will look something like this:

TeamEvent.OnServerEvent:Connect(function(Player)
	if Player:GetRankInGroup(6392114) >= 1 then
		Player.TeamColor = BrickColor.new("Smoky grey")
	end
end)

Remember that you must define the event in both the localscript and the serverscript.

2 Likes

Okay! I’ll get to doing what you and Straphos have said.

2 Likes