Change Team for group role

Hello so I am having a problem with my script were thee is a error saying " GetRankInGroup is not a valid member of RBXScriptSignal". I am not sure what is wrong with my script so if anyone could help me that would be useful! The script is basically were if a MR or HR in my group joins the game they get a team in the group automatically. (I know the rank is the owner rank I was just using that for testing).
Script:

local MRColor = "Really red"
local HRColor = "Teal"
local player = game.Players.PlayerAdded
local ChangeTeam = game.ReplicatedStorage.TeamChange



player:Connect(function()
	if player:GetRankInGroup (6559630) == 255 then
		ChangeTeam:FireServer(BrickColor.new(MRColor))
		print ("Player is MR")
	end
end)

Error:
image

If this in a LocalScript you should be using game.Players.LocalPlayer. But this should really be handled on the server. There is no reason this needs to be handled on the client unless you have a team select menu.

I think your mistake is:

and

The player is an event and you connected it to a function, to check if the player is in a certain group you have to get the actual instance of the player
instead try doing this:

player:Connect(function(plr)
    if plr:GetRankInGroup (6559630) == 255 then
        ChangeTeam:FireServer(BrickColor.new(MRColor))
        print ("Player is MR")
    end
end)

sorry if I’m bad at explaining

Hoped I helped

So how would you change it the the client side? When I changed it to LocalPlayer it still had the error (I changed the script to a LocalScript to test it out. I originally had it as a normal script.

On the client side are you trying to figure out all the players are in a certain group or just the client?

So I want it so when a user joins it will check there rank and if it is the MR rank (the rank number I put) it will put them in a certain team. That is why I put the player added event. I also did this in a normal script not a server side script.

Well on the client-side you wouldn’t need the player added because the script runs when they join. You just have to check if they are in the group, and just to make sure you said this was in a Local Script(The script with a person on it)?

local MRColor = "Really red"
local HRColor = "Teal"
local player = game.Players.LocalPlayer -- Used localPlayer instead of PlayerAdded
local ChangeTeam = game.ReplicatedStorage.TeamChange

if player:GetRankInGroup (6559630) == 255 then -- Removed the event
	ChangeTeam:FireServer(BrickColor.new(MRColor))
	print ("Player is MR")
end

No it was not in a local script. That is why I did not put the localplayer. I did it in the “script” type of script if that makes sense. image

Oh, okay. That is actually a server side script. I think people usually just call it a script because it’s easier. Where is the script located?

It is located in server script service. So what type of script should it be in? I used the code you put and I still got the error. I think it is something to do with “GetRankInGroup” which is strange because I used the same code in another project I made (a rank only game).

Okay since it’s server-sided (and I think it should be), you should try this:

local MRColor = "Really red"
local HRColor = "Teal"
local player = game.Players.PlayerAdded
local ChangeTeam = game.ReplicatedStorage.TeamChange

player:Connect(function(plr) -- plr is the Player that joined the game
    if plr:GetRankInGroup (6559630) == 255 then --  used plr:GetRankInGroup (6559630) == 255 because player is the event
        ChangeTeam:FireServer(BrickColor.new(MRColor))
        print ("Player is MR")
    end
end)

Did it work? Was it the same error?

I did it but I still got the same error.

Have you considered not saving a Event in a variable? Just seems like added complexity to this script. Also, no need to use a RemoteEvent on 100% Server Sided communication (since it won’t work). That’s the purpose of BindeableEvents. (This also includes storing the RemoteEvent in an area of the data model that the client can access, if it has no use for the client then put it in ServerStorage)

local MRColor = "Really red"
local HRColor = "Teal"
local ChangeTeam = game.ReplicatedStorage.TeamChange

game.Players.PlayerAdded:Connect(function(plr) -- plr is the Player that joined the game
    if plr:GetRankInGroup (6559630) == 255 then --  used plr:GetRankInGroup (6559630) == 255 because player is the event
        ChangeTeam:FireServer(BrickColor.new(MRColor))
        print ("Player is MR")
    end
end)

I tested it out, and it worked for me, I’m not sure what’s wrong.
Sorry if I wasn’t that much help

So you do not need to do the game.ReplicatedSyotrage.TeamChange because team change it the RemoteEvent. How would that then effect the script? Sorry I am quite new to scripting. Also I still get the exact error using your script.

This was originally why I thought this was in a LocalScript because RemoteEvents are used for Client to Server communication, hense why the function it uses is named :FireServer(). You can’t use these for doing cross script communication and instead should be using BindableEvents. The orgionally error could very well be do to over complication by storing the the Player event (PlayerAdded) to a variable.

So it would be

local MRColor = "Really red"
local HRColor = "Teal"
local ChangeTeam = game.ReplicatedStorage.TeamChange

game.Players.PlayerAdded:Connect(function(plr)
	if plr:GetRankInGroup (6559630) == 255 then 
		ChangeTeam:Fire(BrickColor.new(MRColor))
		print ("Player is MR")
	end
end)

Yes, but you could just leave all the code in the event at the part where you fire it

I did that but still getting the same exact error/

1 Like

Is there any other code in the script? Are you sure it is the exact same error? Because I tried it and it worked.