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.
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
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.
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
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.
Have a remote event in replicated storage (local remote = game.ReplicatedStorage.ChangeTeam)
On your client hook remote:FireServer() into your click function.
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
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.
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.
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.
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.
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.
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.