I’m trying to add a minigames feature to my game.
Sometimes, the round system just stops working and just says “Spleef!” at the top.
ServerScript in ServerScriptService:
local MinigamePlayers = game.Workspace.MinigamePlayers
local PeopleInSpleef = game.Workspace.PeopleInSpleef
local inRound = game.ReplicatedStorage.Values.InRound
local status = game.ReplicatedStorage.Values.Status
local spleef = game.Workspace.Maps.Spleef
local spleefSpawns = spleef.Spawns:GetChildren()
local lobbySpawn = game.Workspace.MinigameSpawn
local boughtBlocks = game.ReplicatedStorage.Events.PlayerBoughtBlocks
local TweenService = game:GetService("TweenService")
local intermission = 15
local function getRandomBrickColor()
local randomR = math.random(0, 255) / 255
local randomG = math.random(0, 255) / 255
local randomB = math.random(0, 255) / 255
local randomColor = Color3.new(randomR, randomG, randomB)
local brickColor = BrickColor.new(randomColor)
return brickColor
end
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Sine) -- Time to completion and easing style.
local tweenGoal = {Transparency = 1} -- Properties and the wanted values.
local function spleef()
for _, v in pairs(spleef.SpleefParts:GetChildren()) do
if v:IsA("BasePart") and v.Name == "SpleefPart" then
local tween = TweenService:Create(v, tweenInfo, tweenGoal)
v.Touched:Connect(function()
v.CanTouch = false -- 'v' part will not trigger `Touched` events until re-enabled.
tween:Play()
task.wait(2) -- Wait for tween to complete.
tween.Completed:Wait()
v.CanCollide = false
end)
end
end
end
local function round()
while true do
inRound.Value = false
for i, plr in pairs(PeopleInSpleef:GetChildren()) do
plr.Parent = MinigamePlayers
plr:PivotTo(lobbySpawn.CFrame)
end
if #MinigamePlayers:GetChildren() >= 2 then
for i = intermission, 0, -1 do
if #MinigamePlayers:GetChildren() >= 2 then
task.wait(1)
status.Value = "Game will start in "..i.." seconds."
else
while #MinigamePlayers:GetChildren() < 2 do
status.Value = "Waiting for enough players..."
task.wait(1) -- Reduced frequency of wait
end
task.wait(1)
status.Value = "Game will start in "..i.." seconds."
end
end
else
while #MinigamePlayers:GetChildren() < 2 do
status.Value = "Waiting for enough players..."
task.wait(1) -- Reduced frequency of wait
end
for i = intermission, 0, -1 do
if #MinigamePlayers:GetChildren() >= 2 then
task.wait(1)
status.Value = "Game will start in "..i.." seconds."
else
while #MinigamePlayers:GetChildren() < 2 do
status.Value = "Waiting for enough players..."
task.wait(1) -- Reduced frequency of wait
end
task.wait(1)
status.Value = "Game will start in "..i.." seconds."
end
end
end
inRound.Value = true
status.Value = "Spleef!" -- change this to a function later when we add more minigames
for i, plr in pairs(MinigamePlayers:GetChildren()) do
plr.Parent = PeopleInSpleef
plr:PivotTo(spleefSpawns[math.random(1, 12)].CFrame)
end
task.spawn(spleef)
while #PeopleInSpleef:GetChildren() > 1 do
task.wait(1) -- Reduced frequency of wait
end
local PeopleInSpleefTable = PeopleInSpleef:GetChildren()
print(PeopleInSpleefTable[1].." won.")
local winner = PeopleInSpleefTable[1]
local winnerPlr = game.Players:GetPlayerFromCharacter(winner)
local newPart = Instance.new("Part")
newPart.Size = Vector3.new(3, 3, 3)
newPart.BrickColor = getRandomBrickColor()
newPart.Position = Vector3.new(math.random(80, 160), 80, math.random(-50, 50))
newPart.Parent = game.Workspace
winnerPlr:WaitForChild("leaderstats"):WaitForChild("Blocks").Value += 1
boughtBlocks:FireAllClients(winnerPlr.Name.." just won the minigame and got a block!", "#ff1100")
winner:PivotTo(lobbySpawn.CFrame)
winner.Parent = game.Workspace.MinigamePlayers
task.wait(4)
for _, v in pairs(spleef.SpleefParts:GetChildren()) do
v.CanCollide = true
v.CanTouch = true
v.Transparency = 0 -- Fixed transparency reset
end
end
end
task.spawn(round)