First, let's reduce that while loop. A countdown is a very simple loop, a numeric for:
local timeLimit = 60*10
while true do
local h = script.Parent
for curTime = timeLimit, 0, -1 do
local minutes = math.floor(timeLimit/60)
local seconds = timeLimit%60
h.Text = (minutes < 10 and "0" or "") .. minutes .. ":" .. (seconds < 10 and "0" or "") .. seconds
wait(1)
end
h.Parent = nil
end
Now, to make everyone stop moving, we loop through the Table returned by GetPlayers() using a generic for:
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.WalkSpeed = 0
end
end
Since the first code block runs in an infinite loop, you have to insert that WalkSpeed code into the loop for it to ever be run, like so:
local timeLimit = 60*10
while true do
local h = script.Parent
for curTime = timeLimit, 0, -1 do
local minutes = math.floor(timeLimit/60)
local seconds = timeLimit%60
h.Text = (minutes < 10 and "0" or "") .. minutes .. ":" .. (seconds < 10 and "0" or "") .. seconds
wait(1)
end
h.Parent = nil
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Character and player.Character:FindFirstChild("Humanoid") then
player.Character.Humanoid.WalkSpeed = 0
end
end
end
2 comments
The note on out-of-order calling is incorrect, since the
EndGamefunction is global. https://scriptinghelpers.org/questions/16395/what-are-the-differences-between-local-function-and-functionInteresting... Thanks for the correction! Edited...