Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How does this work?

I've been dissecting this huge script for a while now and I've run across some code that I don't understand how it works. Part of the reason I'm trying to understand this is to use the correct table of current survivors later in the code. If anyone can give me insight on this, it would be greatly appreciated. I know it's a lot to ask.

function StartWave()
WaveTime = 40
local pSurvivors = Game:GetService("Players"):GetChildren()
local nPlayers = 0
for Index, Survivor in pairs(pSurvivors) do
if Playing[Survivor] then
nPlayers = nPlayers + 1
end
end
if nPlayers == 0 then Talk("No Players?", 4, "Then skip this round") return true end
Survivors = {}
for Index, Survivor in pairs(pSurvivors) do
if Playing[Survivor] then
pcall(function()
Survivor.Character:MoveTo(Vector3.new(math.random(-331, -307), 351, math.random(-124, -100)))
while (Vector3.new() - Survivor.Character.Humanoid.Torso.Position).magnitude < 50 do
Survivor.Character:MoveTo(Vector3.new(math.random(-331, -307), 351, math.random(-124, -100)))
end
Survivor.Character.Humanoid.Died:connect(function() Survivors[Survivor] = nil end)
Survivors[Survivor] = true
WaveTime = WaveTime + 3.75
end)
end
end
WaveTime = math.floor(WaveTime)
Talk("Starting game...", 2, "")
HorrorSound:Play()
for i = WaveTime, 0, -1 do
Talk(i .. " seconds", 1,  "until the round ends")
local nSurvivors = 0
for Survivor in pairs(Survivors) do
nSurvivors = nSurvivors + 1
end
if nSurvivors == 0 then
LostSound:Play()
Talk("All players died!", 3, "")
break
end

And here's the other function...

function EndWave()
PingSound:Play()
Talk("Game over!", 4, "")
local nSurvivors = 0
for Survivor in pairs(Survivors) do
nSurvivors = nSurvivors + 1
end
local Index = 1
local sSurvivors = ""
for Survivor in pairs(Survivors) do
if Index > 1 then
if Index == nSurvivors then
sSurvivors = sSurvivors .. " and "
else
sSurvivors = sSurvivors .. ", "
end
end
sSurvivors = sSurvivors .. Survivor.Name
Index = Index + 1
end
if nSurvivors > 0 then
local Points = math.ceil(WavePoints / nSurvivors)
for Survivor in pairs(Survivors) do
pcall(function() Survivor.leaderstats.Points.Value = Survivor.leaderstats.Points.Value + Points end)
pcall(function() Survivor.Character:BreakJoints() end)
pcall(function() for Index, Value in pairs(Badges) do if Survivor.leaderstats.Points.Value >= Index then AwardBadge(Survivor, Value) end end end)
end
Talk(sSurvivors .. " survived and got " .. Points .. " points.", 4, "")
else
Talk("You all died", 4, "Nobody gets any points.")
end
end

Once again, thanks.

1 answer

It looks to me like your second function is playing an end sound, telling everyone Game Over then checking who is a survivor. The first one is starting it, setting up, running a timer, checking for players.

This discussion is preserved as it was. New answers, comments, and votes are closed.