Hi!
Recently, me and my group have been working on a Minigames title. This ModuleScript handles the games, ofc. For some reason, it will randomly despawn it. What have I done wrong?
the code | it's really long, so im hiding it to make it look cleaner
local module = {}
local AlivePlayers = {}
local MiniGames = {"4Blocks","6Blocks"}
local MapStars = {
["4Blocks"] = 4, -- Amount
["6Blocks"] = 2,
}
function module.Stars(Map)
for i, Star in pairs(MapStars) do
return MapStars
end
end
function module.ChooseMiniGame()
local RandomGame = MiniGames[math.random(1, #MiniGames)]
if RandomGame then
if RandomGame == "4Blocks" then
module.Start4Blocks(RandomGame)
elseif RandomGame == "6Blocks" then
module.Start6Blocks(RandomGame)
end
return RandomGame
end
end
function module.DeSpawnBlocks(Event)
local EventFolder = game.Workspace:FindFirstChild("EventFolder")
if EventFolder then
EventFolder:Destroy()
end
end
function module.SpawnBlocks(Event)
module.DeSpawnBlocks()
wait(4)
local EventFolder = game.ReplicatedStorage:FindFirstChild(Event):Clone()
EventFolder.Parent = workspace
EventFolder.Name = "EventFolder"
end
function module.Start4Blocks(GameName)
module.SpawnBlocks(GameName)
for i, player in pairs(game.Players:GetPlayers()) do
local HumaniodRootPart = player.Character:FindFirstChild("HumanoidRootPart")
if HumaniodRootPart then
HumaniodRootPart.Anchored = true
HumaniodRootPart.CFrame = CFrame.new(game.Workspace:FindFirstChild("EventFolder"):FindFirstChild("MiddilePart").Position) + Vector3.new(0,10,0)
wait(1.05)
HumaniodRootPart.Anchored = false
else
local Torso = player.Character:FindFirstChild("Torso")
if Torso then
Torso.Anchored = true
Torso.CFrame = CFrame.new(game.Workspace:FindFirstChild("EventFolder"):FindFirstChild("MiddilePart").Position) + Vector3.new(0,10,0)
wait(1.05)
Torso.Anchored = false
end
end
end
end
function module.Start6Blocks()
end
function module.EndRound()
end
function module.RemovePlayer(player)
if AlivePlayers[player] then
table.remove(AlivePlayers,player)
AlivePlayers[player] = nil
end
end
function module.AddPlayer(player)
table.insert(AlivePlayers,player)
print("Working")
end
return module
So, this is what’s REALLY happening:
It’s working, but it is for some reason re choosing the minigame over and over, which makes it despawn.
I can tell that because the text changes to “6Blocks” and then after a bit despawns.
function module.SpawnBlocks(Event)
module.DeSpawnBlocks()
wait(4)
local EventFolder = game.ReplicatedStorage:FindFirstChild(Event):Clone()
EventFolder.Parent = workspace
EventFolder.Name = "EventFolder"
end
yeah when i ran it i found nothing, it seems that it’s not an error and just that you past over something, please try and see if you could try and modify the scripts that despawn or spawn blocks.
function module.SpawnBlocks(Event)
module.DeSpawnBlocks()
wait(4)
local EventFolder = game.ReplicatedStorage:FindFirstChild(Event):Clone()
EventFolder.Parent = workspace
EventFolder.Name = "EventFolder"
end