I was messing around with free-model scripts, for my new Squid Game-based game on Roblox, and I can’t unloop the game events.
- Alright, so I have been working on a Red-Light, Green-Light Game on Roblox, where I have been trying to change up the scripts so I can advance in my knowledge, but I can’t manage to unloop the game events (Whenever I complete the events, it restarts and make me do everything). Does anyone know how to fix this loop.
local gameLength = 120
game.Players.PlayerAdded:Connect(function(plr)
local ls = Instance.new("Folder", plr)
ls.Name = "leaderstats"
local cash = Instance.new("IntValue", ls)
cash.Name = "Cash"
end)
local playersAlive = {}
local playersCompleted = {}
local redLight = false
game:GetService("RunService").Heartbeat:Connect(function()
for i, player in pairs(game.Players:GetPlayers()) do
if player.Character and player.Character:FindFirstChild("Humanoid") then
if player.Character.Humanoid.MoveDirection.Magnitude > 0 and redLight and table.find(playersAlive, player) then
player.Character.Humanoid.Health = 0
script.Shot:Play()
end
end
end
end)
while true do
wait(1)
workspace.SquidGame.PreGameBarrier.CanCollide = true
workspace.SquidGame.EndGameBarrier.CanCollide = false
workspace.SquidGame.Doll.Head.Orientation = Vector3.new(0, 0, 0)
for i, player in pairs(game.Players:GetPlayers()) do
player:LoadCharacter()
table.insert(playersAlive, player)
player.Character.Humanoid.Died:Connect(function()
table.remove(playersAlive, table.find(playersAlive, player))
end)
end
game.ReplicatedStorage.SquidGameRE:FireAllClients("status", "Game starting..", Color3.fromRGB(255, 255, 255))
wait(30)
workspace.SquidGame.PreGameBarrier.CanCollide = false
local timeLeft = gameLength
spawn(function()
while timeLeft > 0 and #playersAlive > 0 do
timeLeft -= 1
local mins = math.floor(timeLeft / 60)
local secs = timeLeft % 60
if string.len(mins) < 2 then mins = "0" .. mins end
if string.len(secs) < 2 then secs = "0" .. secs end
game.ReplicatedStorage.SquidGameRE:FireAllClients("timer", mins .. ":" .. secs)
wait(1)
end
end)
workspace.SquidGame.EndGameBarrier.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
table.remove(playersAlive, table.find(playersAlive, player))
table.insert(playersCompleted, player)
game.ReplicatedStorage.SquidGameRE:FireClient(player, "barrier", workspace.SquidGame.EndGameBarrier)
end
end)
while timeLeft > 0 and #playersAlive > 0 do
game.ReplicatedStorage.SquidGameRE:FireAllClients("status", "GREEN LIGHT", Color3.fromRGB(0, 255, 0))
local randomSpeed = math.random(10, 13)/10
script.Sound.PlaybackSpeed = randomSpeed
script.Sound:Play()
script.Sound.Ended:Wait()
game:GetService("TweenService"):Create(workspace.SquidGame.Doll.Head, TweenInfo.new(0.3), {Orientation = Vector3.new(0, 180, 0)}):Play()
redLight = true
game.ReplicatedStorage.SquidGameRE:FireAllClients("status", "RED LIGHT", Color3.fromRGB(255, 0, 0))
wait(math.random(1, 5))
game:GetService("TweenService"):Create(workspace.SquidGame.Doll.Head, TweenInfo.new(0.3), {Orientation = Vector3.new(0, 0, 0)}):Play()
redLight = false
end
for i, player in pairs(playersAlive) do
player.Health = 0
script.Shot:Play()
end
for i, player in pairs(playersCompleted) do
player.leaderstats.Cash.Value += math.floor(0 / #playersCompleted)
end
end
- I tried changing the following script to false:
while true do
wait(1)
-
In result of this, on joining of the game, the camera view would be stuck in a random position of the map. I don’t know whether this is due to any other game settings or just the Game Event Script.
-
If you know a solution, please state so.