Hey, so I am testing with a Round-Based game. Everything works fine, except one of the players found a bug. If the player turns on AFK mode right after Intermission hits 0, then it adds the player into the _G.gameplayers
table, but it doesn’t teleport them into the round (essentially giving that player a free win).
Here is the code:
while game.Players.NumPlayers < 2 do
status.Value = "There Needs to be at least 2 Players to Begin"
repeat wait(2) until game.Players.NumPlayers >= 2
end
for i = 15,0,-1 do
status.Value = "Intermission... "..i
wait(1)
end
_G.gameplayers = {}
for i, v in pairs(game.Players:GetPlayers()) do
if v then
if playerFolders[v.Name].isAFK.Value == false then
table.insert(_G.gameplayers, v.Name)
else
print(v.Name.." is currently idle")
end
end
end
-- FIX AFK GLITCH - if player hits AFK in this moment, they are in table but not in round
local spleefArena = game.ServerStorage:WaitForChild("SpleefArena")
if #_G.gameplayers >= 2 then
status.Value = "Teleporting Players to Arena"
serverMode.Value = "Choosing"
wait(1)
local gameModes = game.ServerStorage:WaitForChild("Gamemodes"):GetChildren()
local chosenMode = gameModes[math.random(1, #gameModes)]
local SpleefSpawns = game.Workspace:WaitForChild("SpleefSpawns"):GetChildren()
local LavaSpleefSpawns = game.Workspace:WaitForChild("LavaSpleefSpawns"):GetChildren()
if chosenMode.Value == "Normal" then
mode.Value = "Mode: Normal"
serverMode.Value = "Normal"
-- No real changes for Normal Mode
-- Disable AFK Change Ability
for i, v in pairs(game.Players:GetPlayers()) do
if v then
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(v.UserId, 6905258) then
game.Workspace[v.Name]:WaitForChild("Humanoid").WalkSpeed = 19
else
game.Workspace[v.Name]:WaitForChild("Humanoid").WalkSpeed = 16
end
end
end
for i, v in pairs(game.Players:GetPlayers()) do
if v then
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(v.UserId, 6935643) then
game.Workspace[v.Name]:WaitForChild("Humanoid").JumpPower = 35
else
game.Workspace[v.Name]:WaitForChild("Humanoid").JumpPower = 0
end
end
end
spleefArena:WaitForChild("Normal"):Clone().Parent = mapStorage
for _, player in pairs(game.Players:GetPlayers()) do
if player and #SpleefSpawns > 0 and playerFolders[player.Name].isAFK.Value == false then
local playerRoot = player.Character:WaitForChild("HumanoidRootPart")
local allSpleefSpawns = math.random(1, #SpleefSpawns)
local randomSpawn = SpleefSpawns[allSpleefSpawns]
if randomSpawn and playerRoot then
game.ReplicatedStorage:WaitForChild("AFKRound"):FireClient(player, "InRound")
table.remove(SpleefSpawns, allSpleefSpawns)
playerRoot.Anchored = true
playerRoot.CFrame = CFrame.new(randomSpawn.Position + Vector3.new(0, 1, 0))
wait()
end
end
end
wait(2)
for _, player in pairs(game.Players:GetPlayers()) do
if player and playerFolders[player.Name].isAFK.Value == false then
local playerRoot = player.Character:WaitForChild("HumanoidRootPart")
wait()
playerRoot.Anchored = false
end
end
wait(3)
for _, player in pairs(game.Players:GetPlayers()) do
if player and playerFolders[player.Name].isAFK.Value == false then
local playerRoot = player.Character:WaitForChild("HumanoidRootPart")
wait()
playerRoot.Anchored = false
end
end
Keep in mind, this is only a portion of the full script - this portion is where the bug is occurring, right after intermission and before teleportation.
If anyone has any idea how I could fix this bug please let me know.
I have tried inserting code into different sections of the script that check if the player’s AFK value is true and if it is then it updates the table, example of that here:
for _, player in pairs(game.Players:GetPlayers()) do
if player then
if playerFolders[player.Name].isAFK.Value == true then
local Update = {}
for _, Player in pairs(game.Players:GetPlayers()) do
if Player then
for i, v in pairs(_G.gameplayers) do
if v ~= Player.Name then
table.insert(Update,1,v)
end
end
end
end
_G.gameplayers = Update
end
end
end
Anyways, thanks for the help!