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

For Loop CRASHES PC?

So, i have a for loop. So when i run this for loop it makes my CPU and RAM SKYROCKET and almost crash my PC! Can someone explain why its doing this and maybe a way to fix it? Ty. :)

for i = 25, 0, -1 do -- Timer
   killerGui.Text = "Time Left: " .. i
	message3.Text = "Time Left: " .. i
	wait(1)
	local event
event = killer.Character.Humanoid.Died:connect(function()
 p = game.Players:GetChildren()
for i = 1,#p do
  p[i].Character.Head:remove()
end

print("Killer has died!")
round = ("over1")
wait(1)

event:disconnect()
end)
	
	round = true
	
    end

2 answers

for i = 1, 25, -1 do -- Timer
   killerGui.Text = "Time Left: " .. i
    message3.Text = "Time Left: " .. i
    wait(1)
    local event = killer.Character.Humanoid.Died:connect(function() --This won't work, 
	 p = game.Players:GetChildren()
	for i = 1,#p do
		  p[i].Character.Head:remove()
	end
end

print("Killer has died!")
round = ("over1")
wait(1)

event:disconnect() --Can't index a local variable outside of the loop
end)

    round = true --You just changed a string value to a bool value. Not wise.

    end -- Not needed.

You really should rewrite this, there's a lot of things wrong with it. Anywho, I commented the lines I fixed, but there are still some in there.

1 comment

0

What are the other errors? Also, the other "End" is to end the function it was originally within.

To crash the Game Client, put this code in a Local Script, and put the Local Script in StarterGui:

Instance.new("ManualSurfaceJointInstance", game.Workspace.CurrentCamera)

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