Hello! So I have created a code which is 2 parts, a LocalScript and ServerScript. The LocalScript’s location is in StarterGui, and the ServerScript’s location is in ServerScriptService. There is a RemoteEvent in ReplicatedStorage as well. The script is not working, and I don’t really know what’s happening.
LocalScript:
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if string.sub(Message, 1, 11) == "!TeamAssign" and Player:GetRankInGroup(11941815) >= 15 and Player.TeamColor == BrickColor.new("Pastel orange") then
game.ReplicatedStorage.AssignTeams:FireServer()
end
end)
end)
ServerScript:
game.ReplicatedStorage.AssignTeams.OnServerEvent:Connect(function()
game.Players.PlayerAdded:Connect(function(Player)
local GroupID = 11941815
if Player:GetRankInGroup(GroupID) == 5 then
Player.TeamColor = BrickColor.new("Salmon")
else
if Player:GetRankInGroup(GroupID) == 6 then
Player.TeamColor = BrickColor.new("Sage green")
else
if Player:GetRankInGroup(GroupID) == 7 then
Player.TeamColor = BrickColor.new("Buttermilk")
end
end
end
end)
end)
From what I understand, this script should be working. (Also, please don’t send any other links from the DevForum, as this system is custom to fit my game.) Thanks in advance!
I see your issue regarding this script and I have a new script relative to this one that has the same objective you are trying to do.
I recommend re starting the script with this:
game.Players.PlayerAdded:Connect(function(player)
for ids,team in pairs(groups) do
local rankInGroup = player:GetRankInGroup(ids)
if rankInGroup > 250 then
player.Team = game.Teams[team] --Change this to the specific team
elseif rankInGroup > 0 then
player.Team = game.Teams[team]
end
end
end)
I had tried using a for loop (for i = 1, #Players do) with the players being a variable of game.Players:GetPlayers, however I scrapped it once the script didn’t work. Perhaps I should try adding prints?
Would this work? Because if so, It’s a problem with the LocalScript.
game.ReplicatedStorage.AssignTeams.OnServerEvent:Connect(function()
local GroupID = 11941815
local Players = game.Players:GetPlayers()
for i = 1, #Players do
local CurrentPlayer = Players[i]
if CurrentPlayer:GetRankInGroup(GroupID) == 5 then
CurrentPlayer.TeamColor = BrickColor.new("Salmon")
else
if CurrentPlayer:GetRankInGroup(GroupID) == 6 then
CurrentPlayer.TeamColor = BrickColor.new("Sage green")
else
if CurrentPlayer:GetRankInGroup(GroupID) == 7 then
CurrentPlayer.TeamColor = BrickColor.new("Buttermilk")
end
end
end
end
end
The for loop is basically going through 1 player at a time, then it continues the script until it finds their rank and teams them with that rank color.
local Players = game:GetService("Players")
local Storage = game:GetService("ReplicatedStorage")
local TeamEvent = Storage:WaitForChild("AssignTeams")
Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(Message)
if string.lower(string.sub(Message, 1, 11)) == "!teamassign" and Player:GetRankInGroup(11941815) >= 15 and Player.TeamColor == BrickColor.new("Pastel orange") then
TeamEvent:FireServer()
end
end)
end)
local GroupID = 11941815
local Storage = game:GetService("ReplicatedStorage")
local TeamEvent = Storage:WaitForChild("AssignTeams")
TeamEvent.OnServerEvent:Connect(function(Player)
if Player:GetRankInGroup(GroupID) == 5 then
Player.TeamColor = BrickColor.new("Salmon")
elseif Player:GetRankInGroup(GroupID) == 6 then
Player.TeamColor = BrickColor.new("Sage green")
elseif Player:GetRankInGroup(GroupID) == 7 then
Player.TeamColor = BrickColor.new("Buttermilk")
end)
end)
I’ve made a few slight, changes, I’ve added waits to make sure instances load before the script is executed, I’ve made it so that if different capitalisations of the same message are chatted the script will still detect them, I’ve removed the PlayerAdded event from the OnServerEvent event handler as it wouldn’t work, whenever “FireServer()” is called from a client script, the player instance pertinent to that client is always automatically passed as an argument to any function connected to the corresponding OnServerEvent event handler, as such all we need to do is simply declare a parameter in the connected function to handle this passed object. I’ve also changed the logic of the conditional statements, “elseif” allows you to check multiple conditions within the same conditional chain.
It’s making it check if the Rank is more or equal to 15 and then it fires the event. In the event script, it only checks if the rank is 5, 6, or 7, which makes it completely useless.