I’m trying to remake a modular round system from a post I made a fairly long time ago to have overall better readability. The issue is that, in the DevForum post, there was a specific lines of code, which is this:
roundHandler.StartCountdown(function(index) -- Start countdown
print("Countdown:", index) -- Print the current time
end)
Whenever I try to copy that, it refuses to print. Why is that?
RoundHandler
--[[MODULE SCRIPT]]--
local RoundModule = require(script:WaitForChild("RoundModule"))
--[[GAMEPLAY LOOP]]--
while task.wait() do
RoundModule:Intermission(function(INDEX)
print("Time Remaining:", INDEX)
end)
--
RoundModule:Start()
end
RoundModule
--[[SERVICES]]--
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--[[FOLDERS]]--
local MAPS = ReplicatedStorage:WaitForChild("Maps")
--[[VARIABLES]]--
local Minimum_Players = 3
local Base_Intermission = 3
local Round_Timer = 300
--[[MODULE]]--
local RoundHandlerModule = {}
function RoundHandlerModule:Intermission(INDEX, LIMIT)
LIMIT = LIMIT or Base_Intermission
for INDEX = LIMIT, 0, -1 do
task.wait(1)
end
end
function RoundHandlerModule:Start()
print("Work")
end
return RoundHandlerModule
It seems you`re trying to pass a function as a first value to the RoundHandler but the ModuleScript refers to the first value, INDEX, as a number, so it causes error.
A potential workaround would be smt like that:
function RoundHandlerModule:Intermission(MANAGER, LIMIT)
LIMIT = LIMIT or Base_Intermission
for INDEX = LIMIT, 0, -1 do
MANAGER(INDEX)
task.wait(1)
end
end
It works, but it’s only printing the initial countdown and not actually printing out how many seconds left.
(For the module script I gave you, Base_Intermission is 3 seconds. The issue is that it’s only printing 3 seconds and not, y’know, actually printing down. The countdown still works however)
--[[MODULE SCRIPT]]--
local RoundModule = require(script:WaitForChild("RoundModule"))
--[[GAMEPLAY LOOP]]--
while task.wait() do
RoundModule:Intermission(function(INDEX)
print("Time Remaining:", INDEX)
end)
--
RoundModule:Start()
end
function RoundHandlerModule:Intermission(MANAGER, LIMIT)
LIMIT = LIMIT or Base_Intermission
--//Intermission Time
for INDEX = LIMIT, 0, -1 do
MANAGER(LIMIT)
LIMIT -= 1
task.wait(1)
end
end
Hey there! I’m glad @Just0_56 could solve it for you. If you didn’t understand, what happens is that, instead of passing the “manager” function to the RoundHandler:Intermission parameter, you passed “Index” instead, and you can’t because the index is locally implemented in the for loop in :Intermission. What I tried to do previously was to have .StartCountdown handling the intermission, and the current index would be passed as a parameter to manager, so you can do anything while that intermission is running. Good luck! ^^