Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I'm making an AFK button, but if there are 2 players and if one is afk, the other player will win?

Asked by 3 years ago

Basically, I've been making a PVP game with rounds. I made an AFK button, everything works fine, but if there are only 2 players and one of them is AFK, the game still starts but the AFK player doesn't join, so the other player automatically wins. Help would be appreciated

(There are 2 values that are inside the player, either "NotPlaying" or "Playing")

Here is the script:

-- Define Variables

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerStorage = game:GetService("ServerStorage")

local MapsFolder = ServerStorage:WaitForChild("Maps")

local Status = ReplicatedStorage:WaitForChild("Status")

local GameLength = 120

local Reward = 35

-- Game Loop

while true do

    Status.Value = "Waiting for enough players"

    repeat wait(1) until game.Players.NumPlayers >= 2

    Status.Value = "Intermission"

    wait(20)

    local AvailableMaps = MapsFolder:GetChildren()

    local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]


    local ClonedMap = ChosenMap:Clone()
    ClonedMap.Parent = workspace

    Status.Value = "Picking a map..."

    local plrs = {}

    for i, player in pairs(game.Players:GetPlayers()) do
        if player:FindFirstChild("Playing") and player then
            table.insert(plrs,player)
        end
    end

    wait(2)

(This is only the part of the script where it adds the players)

0
Can’t you simply check the amount of non afk players and if it is less than 2, then the game wont start JustinWe12 723 — 3y

1 answer

Log in to vote
0
Answered by
Oxprem 140
3 years ago

Your Issue is simple enough to fix. When the round is ready to begin, simply check if there are 2 or more players with Playing true and NotPlaying false. If there are 2 or more players with Playing true and NotPlaying false, then let the round begin. If not, then, like you did at the beginning of the round, wait until there are enough players with AFK Mode Off.

0
Oh wait, it's not working.. What I did was repeat wait(1) until game.Players.NumPlayers >= 2 and game.Players:FindFirstChild("Playing") >= 2. What did I do wrong? DriBowser 55 — 3y
0
What it does is that it stays on the "Waiting for enough players" status even though both players have the value "Playing" inside their player DriBowser 55 — 3y
0
Is it giving you an error? Oxprem 140 — 3y
0
Oh wait, I see the error: you need to do this instead: repeat wait(1) until game.Players.NumPlayers >= 2 and game.Players:FindFirstChild("Playing").Value >= 2 Oxprem 140 — 3y
View all comments (3 more)
0
You didn't put .Value after finding Playing Oxprem 140 — 3y
0
Oh, thank you. DriBowser 55 — 3y
0
No Problem! Oxprem 140 — 3y
Ad

Answer this question