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

Does anyone know how do I fix it?: "A script has been running for a long time, and may be hanging"

I think it has something to do with this piece of code. Its supposed to check if the right amount of people are in the server. If there are enough players it should teleport them to the map, but it doesnt work.

local debounce = false NumPlayers = 2 target = CFrame.new(10, 32.5, 28)

end

if debounce == false then
	debounce = true

while true do

if game.Players.NumPlayers >= NumPlayers then 

	game.StarterGui.ScreenGui.TextLabel.Text = "There are enough players to start the game!"

	wait(5)

	game.StarterGui.ScreenGui.TextLabel.Text = "Teleporting players to the map"

	wait(1)

	for i, player in ipairs(game.Players:GetChildren()) do

if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then

  player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)

else

	game.StarterGui.ScreenGui.TextLabel.Text = "There are not enough players to start the game!"


debounce = false

end

wait()

end end end end

4 comments

0

idk what happened to the script...

0

add to every loop wait(), that most of the times fixes that problem, if it doesn't, try to fix the codeblock

0

pl0x repost the script this is messed

0

and what do you mean with loop? :P (Im still kind of a new scripter)

1 answer

Hello,

Please add a wait() statement in all of your loops (while true do).

If you don't add a wait() it is going to execute the loop in milliseconds which will crash studio and leave the script hanging.

For example:

while true do
	wait() 
	print('Hello World')
end

For more information visit the wiki.

~Frag

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