Hi, I’m wondering why my module isn’t printing anything, even though it should. Any help would be appreciated!
It’s the ChoosePlayer function that’s supposed to print btw
Here’s the module:
local RoundService = {}
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
function RoundService.ChoosePlayer()
local players = Players:GetPlayers()
if #players == 0 then
return warn("theres no players")
end
local chosen = players[math.random(1, #players)]
print(chosen)
return chosen
end
function RoundService.TeleportPlayers(cframe)
local players = Players:GetPlayers()
for i, player in players do
if not player.Character then continue end
player.Character:PivotTo(cframe)
end
end
function RoundService.Countdown(duration)
for i=duration, 1, -1 do
workspace:SetAttribute("Clock", i)
task.wait(1)
end
end
function RoundService.Intermission(INTERMISSION_TIME)
workspace:SetAttribute("Status", "Intermission")
RoundService.Countdown(INTERMISSION_TIME)
end
function RoundService.RunGame(ROUND_TIME,MAP)
workspace:SetAttribute("Status", "Game")
RoundService.TeleportPlayers(MAP.CFrame)
RoundService.Countdown(ROUND_TIME)
RoundService.ChoosePlayer()
end
return RoundService
Server script:
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local RoundService = require(RS.Modules.Services.RoundService)
local MIN_PLAYERS = 1
while true do
task.wait()
if #Players:GetPlayers() >= MIN_PLAYERS then
RoundService.Intermission(10)
workspace:SetAttribute("Status", "Loading map...")
local V_MAPS = RS.Assets.Maps.Vanilla:GetChildren()
local RANDOM_MAP = V_MAPS[math.random(1,#V_MAPS)]
local NEW_MAP = RANDOM_MAP:Clone()
NEW_MAP.Parent = workspace
task.wait(1)
RoundService.RunGame(60,NEW_MAP.Spawn)
else
workspace:SetAttribute("Status", "Waiting for players...")
end
end
Everything BUT the ChoosePlayer works, please help.
On another note, For your yielding functions, I recommend you suffix them with “async”. This clarifies that code proceeding its call cannot run until the function has ended
Yielding functions are functions that pause the caller thread. Roblox’s documentation outlines these functions. The most notable yielding function is task.wait. Any function which calls a yielding function becomes a yielding function, so you would make these changes:
It’s more just a formatting thing.
Roblox functions end in Async if that function can yield. In simpler terms, it will essentially do task.wait() or some other type of waiting (yielding).
For example, the function BadgeService:UserHasBadgeAsync will not always immediately return you if the user has a certain badge, but rather it’ll yield for a bit while it queries the answer from Roblox’s database.
This is not mandatory, nor will it actually change anything about how the code works, it just clarifies what the function does a bit more.