Hello Developers,
I recently came across an issue with my team script detecting if there’s a certain amount of people on a team. For some reason, when players spam clicks the “Host” button, it allows them all to go on the Host team even if I’m detecting that there are 0 players on the team.
Does anyone have any clue on how I can solve this? I’ve tried basically everything I could come up with and there was really no solid solution.
I’m posting my code below.
local ModuleSettings = {
["Group Configuration"] = {
["GroupId"] = PermissionsModule["GroupId"],
["Developer Rank"] = PermissionsModule["Developer"],
["Server Host Rank"] = PermissionsModule["Server Host"],
},
["Gamepass Configuration"] = {
["Unlimited Team Package"] = GamepassModule["Unlimited Teams"],
["Server Host"] = 1689373
},
["Cooldown Table"] = {},
["Previous Host"] = "",
["Host"] = ""
}
-- Code
SwitchTeamRemote.OnServerEvent:Connect(function(Sender, SelectedTeam)
if not ModuleSettings["Cooldown Table"][Sender] then
ModuleSettings["Cooldown Table"][Sender] = 0
end
if tick() - ModuleSettings["Cooldown Table"][Sender] >= 2.5 then
ModuleSettings["Cooldown Table"][Sender] = tick()
local RepStore = DatastoreModule("rep", Sender)
if SelectedTeam == "Host" then
if Sender.Team == TeamService.Host then
return
end
if Sender.Name == ModuleSettings["Previous Host"] then
NotificationRemote:FireClient(Sender, {
["Message"] = "You were the previous host!",
["Status"] = "Error"
})
return
end
ModuleSettings["Previous Host"] = Sender.Name
if #TeamService.Host:GetPlayers() == 0 then
if MarketPlaceService:UserOwnsGamePassAsync(Sender.UserId, ModuleSettings["Gamepass Configuration"]["Unlimited Team Package"]) or MarketPlaceService:UserOwnsGamePassAsync(Sender.UserId, 692897) or Sender.Name == "OS_92" then
Sender.Team = TeamService.Host
Sender:LoadCharacter()
else
if RepStore:Get(0) >= 25 then
Sender.Team = TeamService.Host
Sender:LoadCharacter()
RepStore:Increment(-25)
end
end
else
NotificationRemote:FireClient(Sender, {
["Message"] = "The Host team is full!",
["Status"] = "Error"
})
end
end)