My script works perfectly for all teams, but with the admin team, even if the player’s name is not in the table, they can still join the team. Anyone got any solutions?
local Admins = {}
game.ReplicatedStorage.Remotes.ChangeTeam.Prisoner.OnServerEvent:Connect(function(player, teamColor)
player.TeamColor = teamColor
wait(0.01)
player:LoadCharacter()
end)
game.ReplicatedStorage.Remotes.ChangeTeam.Police.OnServerEvent:Connect(function(player, teamColor)
player.TeamColor = teamColor
wait(0.01)
player:LoadCharacter()
end)
game.ReplicatedStorage.Remotes.ChangeTeam.Admin.OnServerEvent:Connect(function(player, teamColor)
for i,v in pairs(Admins) do
if player.Name == v then
player.TeamColor = teamColor
wait(0.01)
player:LoadCharacter()
end
end
end)
For admin lists, you should use their UserId instead of their username because they can change their name at any time but they can’t change their UserId.
In the code you provided, it’s correct but the list is empty.
I would recommend fixing up your remote events around as from the looks of it, it can be easily exploited to join the admins by firing the prisoner or police remote and just giving it the teamcolor of admins. Is that what you’re referring to?
Then @EmbatTheHybrid is right, that can be exploited. Store the values on the server and just have it detect which event was fired and get the value for that.
Even though your solution has been found, I would recommend cxhanging your code around to this
local Admins = {}
local teams = game:GetService("Teams")
game.ReplicatedStorage.Remotes.ChangeTeam.Prisoner.OnServerEvent:Connect(function(player)
player.TeamColor = teams["Prisoner"].TeamColor
wait(0.01)
player:LoadCharacter()
end)
game.ReplicatedStorage.Remotes.ChangeTeam.Police.OnServerEvent:Connect(function(player)
player.TeamColor = teams["Police"].TeamColor
wait(0.01)
player:LoadCharacter()
end)
game.ReplicatedStorage.Remotes.ChangeTeam.Admin.OnServerEvent:Connect(function(player)
if table.find(Admins, player.UserId) then
player.TeamColor = teams["Admin"].TeamColor
wait(0.01)
player:LoadCharacter()
end
end)
This ensures that exploiters can’t exploit the teams by changing giving the color of the Admin Team, just change the team names around for your team names, never trust the Client
Hmm, maybe revert it to how it was before with looping through the table?
local Admins = {}
local teams = game:GetService("Teams")
game.ReplicatedStorage.Remotes.ChangeTeam.Prisoner.OnServerEvent:Connect(function(player)
player.TeamColor = teams["Prisoner"].TeamColor
wait(0.01)
player:LoadCharacter()
end)
game.ReplicatedStorage.Remotes.ChangeTeam.Police.OnServerEvent:Connect(function(player)
player.TeamColor = teams["Police"].TeamColor
wait(0.01)
player:LoadCharacter()
end)
game.ReplicatedStorage.Remotes.ChangeTeam.Admin.OnServerEvent:Connect(function(player, teamColor)
for _,id in pairs(Admins) do
if player.UserId == id then
player.TeamColor = teams["Admin"].TeamColor
wait(0.01)
player:LoadCharacter()
end
end
end)
Did you remember to change "Admin" to the name of your admin team? If they’re the same, then it could be an incorrect name. Or just to be safe, add a print inside of the if statement to ensure it’s getting through the event
local Admins = {"1636313428"}
local teams = game:GetService("Teams")
game.ReplicatedStorage.Remotes.ChangeTeam.Prisoner.OnServerEvent:Connect(function(player)
player.TeamColor = teams["Prisoner"].TeamColor
wait(0.01)
player:LoadCharacter()
end)
game.ReplicatedStorage.Remotes.ChangeTeam.Police.OnServerEvent:Connect(function(player)
player.TeamColor = teams["Police"].TeamColor
wait(0.01)
player:LoadCharacter()
end)
game.ReplicatedStorage.Remotes.ChangeTeam.Admin.OnServerEvent:Connect(function(player, teamColor)
print(player.UserId)
for _,id in pairs(Admins) do
print(id)
if player.UserId == id then
player.TeamColor = teams["Admin"].TeamColor
wait(0.01)
player:LoadCharacter()
end
end
end)