Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I tried to include more loops, but only the first loop played, what do i do to add more than 1 look?

Asked by 4 years ago

When I tried to build a script, i included more loops. And not every loops played, only the first loop played. Here’s the script I’m into:

local m = Instance.new("Message",Workspace)
m.Text = "REACTOR SABOTAGE -"
wait(0.2)
m.Text = "REACTOR SABOTAGE -M"
wait(0.2)
m.Text = "REACTOR SABOTAGE -ME"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MEL"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELT"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTD"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTDO"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTDOW"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTDOWN"
wait(0.7)
m:Remove()
wait()
local sound = Instance.new("Sound")
sound.Name = "Sound"
sound.SoundId = "http://www.roblox.com/asset/?id=332186658"
sound.Volume = 3
sound.Pitch = 1 
sound.Looped = true
sound.archivable = false
sound.Parent = game.Workspace
wait()
sound:play()
game.Lighting.FogEnd = 600
wait()
while true do
game.Lighting.FogColor = Color3.fromRGB(900,0,0)
wait(1.1)
game.Lighting.FogColor = Color3.fromRGB(255,255,255)
wait(1.1)
end
local m = Instance.new("Hint", game.Workspace)
wait()
local unit = 190
wait()
for i = 1, 190 do
    unit = unit - 1
    m.Text = "Meltdown in"  ..unit.. " Seconds"
    wait(1)
end
while true do
game.Workspace.Baseplate:remove()
game.Workspace.Gravity = 0
game.Workspace.Terrain:ClearAllChildren()
game.Workspace:ClearAllChildren()
end
while true do 
 wait(0.1)
 Hi = game.Players:GetChildren()
 for i = 1,#Hi do
  Hi[i]:kick("DEFEAT! THE IMPOSTOR WAS: Naderssrr")
 end
end

This is the script. Please help me.

2 answers

Log in to vote
0
Answered by
ben0h555 417 Moderation Voter
4 years ago

Simple! This is simply due to how lua functions, when your code hits a loop itll stay on that loop till the loop exits or breaks. So in order to run multiple loops at once you gotta do something fancy, I suggest using the Spawn() function to create another thread!. Heres the edited code!:

local m = Instance.new("Message",Workspace)
m.Text = "REACTOR SABOTAGE -"
wait(0.2)
m.Text = "REACTOR SABOTAGE -M"
wait(0.2)
m.Text = "REACTOR SABOTAGE -ME"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MEL"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELT"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTD"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTDO"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTDOW"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTDOWN"
wait(0.7)
m:Remove()
wait()
local sound = Instance.new("Sound")
sound.Name = "Sound"
sound.SoundId = "http://www.roblox.com/asset/?id=332186658"
sound.Volume = 3
sound.Pitch = 1 
sound.Looped = true
sound.archivable = false
sound.Parent = game.Workspace
wait()
sound:play()
game.Lighting.FogEnd = 600
wait()
while true do
game.Lighting.FogColor = Color3.fromRGB(900,0,0)
wait(1.1)
game.Lighting.FogColor = Color3.fromRGB(255,255,255)
wait(1.1)
end
local m = Instance.new("Hint", game.Workspace)
wait()
local unit = 190
wait()
for i = 1, 190 do
    unit = unit - 1
    m.Text = "Meltdown in"  ..unit.. " Seconds"
    wait(1)
end
spawn(function() --Spawning separate thread to do this loop.
    while true do
    game.Workspace.Baseplate:remove()
    game.Workspace.Gravity = 0
    game.Workspace.Terrain:ClearAllChildren()
    game.Workspace:ClearAllChildren()
    end
end)
while true do 
 wait(0.1)
 Hi = game.Players:GetChildren()
 for i = 1,#Hi do
  Hi[i]:kick("DEFEAT! THE IMPOSTOR WAS: Naderssrr")
 end
end

0
I suggest using coroutines over spawns. JesseSong 3916 — 4y
0
Depends on the use case, in most scenarios it doesnt matter. ben0h555 417 — 4y
Ad
Log in to vote
1
Answered by 4 years ago

Use coroutines, so the loop won't yield the script:

local m = Instance.new("Message",Workspace)
m.Text = "REACTOR SABOTAGE -"
wait(0.2)
m.Text = "REACTOR SABOTAGE -M"
wait(0.2)
m.Text = "REACTOR SABOTAGE -ME"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MEL"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELT"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTD"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTDO"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTDOW"
wait(0.2)
m.Text = "REACTOR SABOTAGE -MELTDOWN"
wait(0.7)
m:Remove()
wait()
local sound = Instance.new("Sound")
sound.Name = "Sound"
sound.SoundId = "http://www.roblox.com/asset/?id=332186658"
sound.Volume = 3
sound.Pitch = 1 
sound.Looped = true
sound.archivable = false
sound.Parent = game.Workspace
wait()
sound:play()
game.Lighting.FogEnd = 600
wait()
coroutine.wrap(function()
    while true do
        game.Lighting.FogColor = Color3.fromRGB(900,0,0)
        wait(1.1)
        game.Lighting.FogColor = Color3.fromRGB(255,255,255)
        wait(1.1)
    end
end)() -- do not delete those two brackets as they will make the coroutine run

local m = Instance.new("Hint", game.Workspace)
wait()
local unit = 190
wait()
for i = 1, 190 do
    unit = unit - 1
    m.Text = "Meltdown in"  ..unit.. " Seconds"
    wait(1)
end
coroutine.wrap(function()
    while true do
        game.Workspace.Baseplate:Destroy() -- remove() is deprecated
        game.Workspace.Gravity = 0
        game.Workspace.Terrain:ClearAllChildren()
        game.Workspace:ClearAllChildren()
        wait() -- without teh wait the loop will crash the game
    end
end)()


while true do 
    wait(0.1)
    Hi = game.Players:GetChildren()
    for i = 1,#Hi do
        Hi[i]:kick("DEFEAT! THE IMPOSTOR WAS: Naderssrr")
    end
end

I haven't tested it, but by logic it should work

0
Thank you so much, the coroutine Script works! Thanks for helping me. Naderssrr 15 — 4y
0
One problem, keep the kick script loop. Naderssrr 15 — 4y
0
It is line 63-69, look closely User#32819 0 — 4y
0
Ok. Naderssrr 15 — 4y

Answer this question