I'm trying to make my own squid game in roblox. So I searched up a tutorial for that and did it. That works. But then I thought "huh, I should add a intermission". So I searched a tutorial for that and then I plugged it into my original script. Then though, the intermission just loops. Anyways here's the code (p.s. i'm a beginner, so expect a rookie mistake)
Main Server Script
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Map = game.Workspace.Map
local Bacon = Map.Bacon
local TimerUI = Map.Timer.UI
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status
local LobbySpawn = game.Workspace.LobbySpawn
local MapSpawn = Map.MapSpawn
local Round_Duration_Seconds = 10
local Intermition_Duration_Seconds = 5
local IsRedLight = ReplicatedStorage.IsRedLight
local SavedPlayerPositions = {} -- Logs all player positions on red light
local SpinTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local OriginalHeadCFrame = Bacon.Head.CFrame
local GreenLightHead = TweenService:Create(Bacon.Head, SpinTweenInfo, {
CFrame = OriginalHeadCFrame
})
local RedLightHead = TweenService:Create(Bacon.Head, SpinTweenInfo, {
CFrame = OriginalHeadCFrame * CFrame.Angles(0,math.rad(180),0)
})
function DressCharacterInSuit(Character)
for _, Object in pairs(Character:GetChildren()) do
if Object:IsA("Shirt") or Object:IsA("Pants") or Object:IsA("ShirtGraphic") then
Object:Destroy()
end
end
local Shirt = Instance.new("Shirt")
Shirt.ShirtTemplate = "rbxassetid://7597521537"
Shirt.Parent = Character
local Pants = Instance.new("Pants")
Pants.PantsTemplate = "rbxassetid://7597288954"
Pants.Parent = Character
end
function SecondsToTimestamp(Seconds)
Seconds = math.max(Seconds,0)
local Minutes = tostring(math.floor(Seconds / 60))
local LeftOverSeconds = tostring(Seconds % 60)
if #LeftOverSeconds == 1 then
LeftOverSeconds = "0"..LeftOverSeconds
end
return tostring(Minutes)..":"..LeftOverSeconds
end
function LogPlayerPositions(Players)
for _, Player in pairs(Players) do
if Player.Character then
local HumanoidRootPart = Player.Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
SavedPlayerPositions[Player] = HumanoidRootPart.Position
end
end
end
end
function IntermissionTimer()
while wait() do
for i = Intermition_Duration_Seconds, 1, -1 do
InRound.Value = false
wait(1)
Status.Value = "Intermission - ".. i .." seconds left"
end
end
end
InRound.Changed:Connect(function()
if InRound.Value == true then
for _, Player in pairs(game.Players:GetChildren()) do
local Char = Player.Character
Char.HumanoidRootPart.CFrame = MapSpawn.CFrame
end
else
for _, Player in pairs(game.Players:GetChildren()) do
local Char = Player.Character
Char.HumanoidRootPart.CFrame = LobbySpawn
end
end
end)
function StartGame()
InRound.Value = true
GreenLightHead:Play()
IsRedLight.Value = false
SavedPlayerPositions = {}
local PlayersInRound = Players:GetPlayers()
local Winners = {}
local SpinDelay = 5
local LastSpin = tick()
local EndTouch
for _, Player in pairs(PlayersInRound) do
Player:LoadCharacter()
DressCharacterInSuit(Player.Character)
end
EndTouch = Map.EndBarrier.Touched:Connect(function(Toucher)
if not Toucher or not Toucher.Parent then
return
end
local TouchChar = Toucher.Parent
local TouchPlayer = Players:GetPlayerFromCharacter(TouchChar)
if TouchPlayer then
table.insert(Winners, TouchPlayer)
local PlayerIndex = table.find(PlayersInRound,TouchPlayer)
if PlayerIndex then
table.remove(PlayersInRound,PlayerIndex)
end
end
end)
for i = Round_Duration_Seconds, 0, -1 do
TimerUI.TimeLabel.Text = SecondsToTimestamp(i)
if IsRedLight.Value then
-- Store positions of players, check if they've moved
for Player, SavedPosition in pairs(SavedPlayerPositions) do
if Player.Character then
local HumanoidRootPart = Player.Character:FindFirstChild("HumanoidRootPart")
if HumanoidRootPart then
if (HumanoidRootPart.Position - SavedPosition).Magnitude >= 1 then
Player.Character:BreakJoints() -- Kill the player
SavedPlayerPositions[Player] = nil
-- Remove player from the round table
local PlayerIndex = table.find(PlayersInRound, Player)
if PlayerIndex then
table.remove(PlayersInRound, PlayerIndex)
end
end
end
end
end
end
if tick()-LastSpin >= SpinDelay then -- Has 5 seconds gone since the last turn
if IsRedLight.Value == true then
-- Make it green
IsRedLight.Value = false
GreenLightHead:Play()
else
-- Make it red
IsRedLight.Value = true
RedLightHead:Play()
LogPlayerPositions(PlayersInRound)
end
LastSpin = tick()
SpinDelay = SpinDelay * 0.9 -- Make it spin faster each time
end
if #PlayersInRound == 0 then
break
end
task.wait(1) -- Countdown Delay
end
-- Well, GAME OVER
EndTouch:Disconnect()
print("Round Over!")
end
-- Main Game Loop
while true do
IntermissionTimer() -- Start the Intermission
StartGame() -- Start the Game
end
Player GUI Script
local Player = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Label = script.Parent.LightStatus
local Status = game.ReplicatedStorage.Status
Status.Changed:Connect(function()
Label.TextColor3 = Color3.fromRGB(255, 255, 255)
Label.Text = Status.Value
end)
ReplicatedStorage.IsRedLight.Changed:Connect(function(IsRedLight)
if IsRedLight then
Label.Text = "Red Light"
Label.TextColor3 = Color3.fromRGB(255, 0, 0)
else
Label.Text = "Green Light"
Label.TextColor3 = Color3.fromRGB(0, 255, 0)
end
end)

1 comment
remove the while wait do on line 70 and also set in round value to true!