How would I make a Group Ranks team changer?

Okay, so let me explain. I already have a team changer,
Here is the code:

function Click(mouse) 
	if script.Parent.Parent.Parent.Parent.Parent:IsInGroup(10616859) then 
script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new("Storm blue") 
end 
end 

script.Parent.MouseButton1Click:connect(Click) 

I am very new to scripting, I do know some basics and continue to learn. Just I’d like help from now!
Since I’m new please be more helpful then most of the time, thanks!

1 Like

Is there a reason why you overcomplicated it for yourself by doing script.Parent.Parent.Parent … instead of just game.Players.LocalPlayer?

On line two, or three?(Sorry little new to scripting)(I’m learning from a friend)

Both. It isn’t wrong but it isn’t a good idea to do script.Parent.Parent … incase you moved the script.

If you mean like when player joins he will be like “Blue Team” then this is a script for it…

game.Players.PlayerAdded:connect(function(newPlayer)
	local rank = newPlayer:GetRankInGroup(GroupID)
	local teamName = ""
	if rank == 0 then
		teamName = "Visitor"

	end
	newPlayer.TeamColor = game.Teams[teamName].TeamColor
end)

Okay, I’ll change it. It does seem more simple now that I look at it.

Yes, but their clicking on a GUI. It’s a Team Change GUI that I’ve created.

Oh then I will send script for that

Basically, image They would click on Team GUI, it opens all the available teams and I want to make it so one certain team cannot be joined unless their at a Certain Group Rank. I only made it so it’s only a certain group.

Thank you! I’ll try to review the script as best as possible to learn more lua.

The best way to do this would be to use a LocalScript, and reference the Player using game.Players.LocalPlayer :slightly_smiling_face:

You can probably change the Team’s Color by sending a RemoteEvent, from the client to the server to receive it’s changes

--LocalScript
local Player = game.Players.LocalPlayer
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local function Click()
    Event:FireServer()
end

script.Parent.MouseButton1Click:Connect(Click)
--Here, we insert a script inside ServerScriptService to receive the event fired from the client
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(Player)
    if Player:IsInGroup(10616859) then
        Player.TeamColor = BrickColor.new("Storm blue") 
    end
end)
1 Like

From what I’m understanding, this seems like when the player is added? I’m looking for when the button is clicked it will team them that, I may be wrong though?

Actually, it won’t

The Event will only fire once on the server-side when a player clicks the button (As provided in the local-side using the FireServer() function)

Events will only fire when given a specific change to detect

Ah, okay. My bad, I didn’t see the entire script. Just noticed MouseButton1Click. Let me go ahead and test to make sure it works. Thank you!

Well, i’m looking so it is able to be a Group Rank, that seems to be a Group Only team. So I want it to basically be, you click on the GUI if your for example 2+ rank(id) it will let you on the team, otherelse it wont.

When you mean Group Rank, do you mean checking if the Player is in a specific group rank? (0-255)

Yes, basically.
They are in a group,
they must be atleast rank id: 2 or over,
if their not they don’t get teamed.
Got it now?

I see, use the Player:GetRankInGroup function then

Try this inside your server side:

--Here, we insert a script inside ServerScriptService to receive the event fired from the client
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(Player)
    if Player:IsInGroup(10616859) and Player:GetRankInGroup(10616859) >= 2 then
        Player.TeamColor = BrickColor.new("Storm blue") 
    end
end)

Aye, so this is going to do if their atleast rank 2 then they’ll be put on team, any higher ranks will also be put on team?

Yep, this will also check if the Player is in that specific group to prevent any sort of erroring as well, otherwise it’d return back as false and won’t set the TeamColor :wink: