Hello everyone,
Me and my friend Driedus are making a plates of fates game and want to implement an AFK button that makes it so you don’t go into games, this would be super useful as we have made an obstacle course in the lobby. Currently, it puts all the players into the game when it starts but I only want the ones with AFK off to go into the game. Here is the script for the game:
workspace.Extras.Playing.Parent = game.Teams
workspace.Extras.Spectating.Parent = game.Teams
workspace.what.winners.SurfaceGui.TextLabel.Text = "no winners the server just started mate"
wait(5)
print("Loaded")
while true do
local plrs = game.Players:GetChildren()
for i= 1,#plrs do
game.ServerStorage.countdown:Clone().Parent = plrs[i].PlayerGui
end
wait(10)--time between rounds
local plrs = game.Players:GetChildren()
local plate = workspace.Plates:GetChildren()
local tp = workspace.teleport:GetChildren()
if #plrs >= 1 then-- set to 4 when publish for testing do 1
for i= 1,#plrs do
if plrs[i] then
plrs[i].Character.Head.CFrame = CFrame.new(tp[i].Position)
plrs[i].TeamColor = BrickColor.new("Maroon")
plate[i].Transparency = 0
plate[i].Position = plate[i].Position+Vector3.new(0,70,0)
plate[i]:Clone()
plate[i]:Clone().Parent = workspace.ingameplates
plate[i].Position = plate[i].Position+Vector3.new(0,-70,0)
plate[i].Transparency = 1
wait(1)
end
end
wait(1)
for i=1,#plrs do
if plrs[i] then
plrs[i].TeamColor = BrickColor.new("Maroon")
end
end
wait(2)
repeat
local plates = workspace.ingameplates:GetChildren()
local plate = plates[math.random(1,#plates)]
local events = workspace.Events:GetChildren()
local event = events[math.random(1,#events)]
local eventname = event.Name
local plrs = game.Players:GetChildren()
for i= 1,#plrs do
if plrs[i] then
game.ServerStorage.label.TextLabel.Text = eventname
game.ServerStorage.label:Clone().Parent = plrs[i].PlayerGui
end
end
wait(3)
event:Clone().Parent = plate
wait(2)
alive = 0
dead = 0
for _,v in pairs(game.Players:GetChildren()) do
if v.TeamColor.Name == "Maroon" and v.Neutral == false then
alive = alive + 1
local plrname = v.Name
elseif v.TeamColor.Name == "Ghost Grey" and v.Neutral == false then
dead = dead + 1
end
end
until alive == 0 or alive == 1 -- keep at 1 unless test
if alive == 1 then
local team = game.Teams.Playing:GetPlayers()
local winner = team[math.random(1,#team)].Name
local winnerp = game.Players:FindFirstChild(winner)
local wins = winnerp.leaderstats.Wins
wins.Value = wins.Value + 1 --gives winner 1 point
local plrs = game.Players:GetChildren()
for i= 1,#plrs do
if plrs[i] then
game.ServerStorage.label.TextLabel.Text = winner.." has won the game!" --find winner
game.ServerStorage.label:Clone().Parent = plrs[i].PlayerGui
workspace.what.winners.SurfaceGui.TextLabel.Text = winner.." won the last round"
end
end
end
if alive == 0 then
local plrs = game.Players:GetChildren()
for i= 1,#plrs do
if plrs[i] then
game.ServerStorage.label.TextLabel.Text = "Game has ended, nobody won :(" --nobody win
game.ServerStorage.label:Clone().Parent = plrs[i].PlayerGui
workspace.what.winners.SurfaceGui.TextLabel.Text = "nobody won last round"
end
end
end
wait(4)
workspace.ingameplates:ClearAllChildren()
local plrs = game.Players:GetChildren()
for i= 1,#plrs do
if plrs[i] then
game.ServerStorage.label.TextLabel.Text = "A new game will begin shortly." -- yes
game.ServerStorage.label:Clone().Parent = plrs[i].PlayerGui
end
end
wait(5)
else
local plrs = game.Players:GetChildren()
for i= 1,#plrs do
if plrs[i] then
wait(2)
game.ServerStorage.label.TextLabel.Text = "Not enough players, waiting for more.." --not enough ppl
game.ServerStorage.label:Clone().Parent = plrs[i].PlayerGui
end
end
wait(4)
end
end
Just a quick mention, I don’t currently have the script for the button but I can make one if I need to.
Thanks,
Alek