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

This code only runs once and never runs again even with a while wait loop?

Asked by 1 year ago

Title.

Here is my code:

local TweenService = game:GetService("TweenService")
local RS = game:GetService("ReplicatedStorage")

local enemiesFolder = RS.Enemies
local enemySpawn = workspace.EnemySpawns:GetChildren()
local moveToParts = workspace.MoveToParts:GetChildren()

local randomSpawn = enemySpawn[math.random(1, #enemySpawn)]
local randomMoveToPart = moveToParts[math.random(1, #moveToParts)]

local function Round1()

    local Round1Enemy = enemiesFolder.Enemy1:Clone()
    Round1Enemy.Parent = workspace.Enemies
    local currentPivot = randomSpawn:GetPivot()
    Round1Enemy:PivotTo(currentPivot)
    while wait(0.1) do

        Round1Enemy.Torso.CFrame = Round1Enemy.Torso.CFrame * CFrame.new(-1, 0, 0)

    end

end


while wait(5) do
    Round1()
end

1 answer

Log in to vote
0
Answered by 1 year ago

Round1() has its own while wait() do loop. When you run Round1() on line 27 it will continue forever because the loop on lines 17 to 21 will never stop.

0
How would i fix it then? KoalaKo_XD 27 — 1y
0
Replace it with a loop that waits for something like a "repeat until" or a loop with a certain amount of loops virushunter9 943 — 1y
Ad

Answer this question