Hello,
I’m working on a Minigame experience, and I’ve run into a strange issue.
Basically, there is a script named ‘MinigameHandler’ with a ModuleScript as a child with the name of ‘Obby’. The ModuleScript also has an IntValue below it named ‘PlrCount’. The MinigameHandler is located in a Folder inside of ServerScriptService.
Alright so with that out of the way…
Here’s the ‘MinigameHandler’ Script:
local Remotes = game.ReplicatedStorage.Remotes
local GameStorage = workspace.GameStorage
local ServerStorage = game:GetService("ServerStorage")
IntermissionTime = 6 -- // Intermission time (in seconds)
RequiredPlayers = 1 -- // Players required to start
LobbyPosition = workspace.Lobby.SpawnLocation.CFrame
Gamemodes = {}
for _,v in pairs(script:GetChildren()) do
table.insert(Gamemodes, v.Name)
end
function newRound()
local CurrentIntermissionTime = tonumber(IntermissionTime)
repeat wait(1)
CurrentIntermissionTime = tonumber(CurrentIntermissionTime)-1
Remotes.UISendInfo:FireAllClients("Intermission: "..CurrentIntermissionTime)
until tonumber(CurrentIntermissionTime) == 0
local Gamemode = Gamemodes[math.random(1,#Gamemodes)]
game.ReplicatedStorage.GameInSession.Value = true
local MapStorage = ServerStorage.Maps[Gamemode]:GetChildren()
local Map = MapStorage[math.random(1,#MapStorage)]
game.ReplicatedStorage.Remotes.UIMapName:FireAllClients(Map.Name)
local MapClone = Map:Clone()
MapClone.Name = Gamemode
MapClone.Parent = GameStorage
local gamemodeScript = require(script[Gamemode])
gamemodeScript.start(Map, LobbyPosition)
wait(1)
checkForPlayers()
end
function checkForPlayers()
if game.ReplicatedStorage.GameInSession.Value == false then
repeat wait(0.04)
if #game.Players:GetPlayers() < RequiredPlayers then
Remotes.UISendInfo:FireAllClients("Waiting for "..RequiredPlayers.." or more players")
end
until #game.Players:GetPlayers() >= RequiredPlayers
newRound()
end
end
checkForPlayers()
And here’s the ‘Obby’ ModuleScript:
-- // Server Variables
local module = {}
local ServerStorage = game:GetService("ServerStorage")
local Resources = ServerStorage.GameResources
local Remotes = game.ReplicatedStorage.Remotes
local GameStorage = workspace.GameStorage
local PlayerService = game:GetService("Players")
-- // Modifiable Variables
local TimeToStart = 10
-- // Main Script
module.start = function(map,lobbyPosition)
local players = game.Players:GetPlayers()
local spawns = map.Spawns:GetChildren()
local obbyparts = GameStorage["Obby"].ObbyParts:GetChildren()
for i,v in pairs(obbyparts) do
v.Transparency = 0.5
v.CanCollide = false
end
for _,v in pairs(players) do
if v.Character ~= nil and v.Character.Humanoid.Health > 0 then
v.Character.Humanoid.Died:Connect(function()
for i,vv in ipairs(players) do
if v == vv then
table.remove(players,i)
script.PlrCount.Value = #players
end
end
end)
Remotes.UISendInfo:FireAllClients("Race was chosen!")
local spawnPoint = spawns[math.random(1,#spawns)]
-- // Teleport Player
if v.Character ~= nil then
v.Character:MoveTo(spawnPoint.Position)
end
else
-- // Remove Unnecessary Players
for i,vv in ipairs(players) do
if v == vv then
table.remove(players,i)
end
end
end
end
script.PlrCount.Value = #players
-- // Start Minigame
local CurrentTTS = tonumber(TimeToStart)
repeat wait(1)
CurrentTTS = tonumber(CurrentTTS)-1
Remotes.UISendInfo:FireAllClients("Race starting in "..CurrentTTS)
until tonumber(CurrentTTS) == 0
Remotes.UISendInfo:FireAllClients("Race started!")
local Map = GameStorage[script.Name]
for i,v in pairs(obbyparts) do
v.Transparency = 0
v.CanCollide = true
end
-- // Wait for Winner
wait(3)
Remotes.UISendInfo:FireAllClients("Race in session on the map "..Map.Name)
local TouchDebounce = false
Map.WinPart.Touched:Connect(function(hit)
if TouchDebounce == false and hit.Parent:FindFirstChild("Humanoid") and PlayerService:FindFirstChild(hit.Parent.Name) then
TouchDebounce = true
local WinnerPlr = game.Players[hit.Parent.Name]
local Winner = tostring(WinnerPlr.Name)
Remotes.UISendInfo:FireAllClients(Winner.." just won the race!")
wait(2)
if WinnerPlr ~= nil then
WinnerPlr.Character.HumanoidRootPart.CFrame = lobbyPosition
WinnerPlr.Character.Humanoid.Health = WinnerPlr.Character.Humanoid.MaxHealth
WinnerPlr.Backpack:ClearAllChildren()
for i,v in pairs(WinnerPlr.Character:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
else
WinnerPlr.Character.Humanoid.Health = WinnerPlr.Character.Humanoid.Health - WinnerPlr.Character.Humanoid.Health
end
-- // Calculate Amount of Crystals
print("Calculating crystals...")
local PlayerStats = PlayerService[Winner]:WaitForChild("PlayerStats")
local RandomAmount = math.random(2,5)
if PlayerStats["25Mult"].Value == true and PlayerStats["5Mult"].Value == false then
RandomAmount = RandomAmount*1.25
elseif PlayerStats["5Mult"].Value == true then
RandomAmount = RandomAmount*1.5
elseif PlayerStats["25Mult"].Value == false and PlayerStats["5Mult"].Value == false then
RandomAmount = RandomAmount
end
-- // Change Player Values
local function Round(n)
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
end
local RandomAmount = Round(RandomAmount)
PlayerStats.Crystals.Value = PlayerStats.Crystals.Value+RandomAmount
PlayerStats.TotalWins.Value = PlayerStats.TotalWins.Value+1
PlayerStats.SessionWins.Value = PlayerStats.SessionWins.Value+1
wait(3)
print("Cleaning...")
Remotes.UIMapName:FireAllClients("")
Remotes.UISendInfo:FireAllClients("Cleaning up...")
Map:Destroy()
wait(1.5)
print("Done cleaning...")
Remotes.UISendInfo:FireAllClients("Done cleaning!")
end
end)
end
return module
I’m very unsure as to why it stops working. There are no errors in the Output tab, I have multiple other minigame scripts which used to work but don’t anymore either.
It works fine up until the very end, as it still prints “Done cleaning…” and fires the remote. Usually, the MinigameHandler script would then after pick another random minigame.
I’m not very knowledgeable when it comes to ModuleScripts.
I’ve messed with the code in little bits for so long that I eventually ditched the project for a few weeks, coming back now I still can’t find the fix. Any help would be so greatly appreciated!