Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

2 comments

0

How would i fix it then?

0

Replace it with a loop that waits for something like a "repeat until" or a loop with a certain amount of loops

This discussion is preserved as it was. New answers, comments, and votes are closed.