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

How Do I Fix "Infinite yield possible on 'Workspace:WaitForChild("Spawn")"?

Asked by 5 years ago

Heres My Script

local status = game.ReplicatedStorage:WaitForChild("Status")
local players = game.Players:GetChildren()
local maps = game.Lighting.Maps:GetChildren()
local currentmap = game.Workspace:WaitForChild("CurrentMap")
local chosenmap = script:WaitForChild("ChosenMap")
local spawner = game.Workspace:WaitForChild("Spawn")
local choices = {}

--Choose a random map
function choosemap()
  for i = 1,#maps do
 if maps[i]:isA("Model")then
  table.insert(choices,maps[i])
 end
end
local picked = math.random(1,#maps)
chosenmap.Value = choices[picked].Name
end

--Load the map
function loadMap()
 local map = game.Lighting.Maps:FindFirstChild(chosenmap.Value)
 map:Clone().Parent = currentmap
end

--Delete the map
function deleteMap()
 for i,v in pairs(currentmap:GetChildren())do
  if v:isA("Model") then
   v:Destroy()
  end
 end
end

--Teleport all the players
function teleportPlayers()
 for i,v in pairs(players)do
  v.Character.HumanoidRootPart.CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn.CFrame * CFrame.new(math.random(5,10),0,math.random(5,10))
  end
end

--Teleport back the players
function teleportBack()
 for i,v in pairs(players)do
  v.Character.HumanoidRootPart.CFrame = spawner.SpawnLocation.CFrame * CFrame.new(math.random(5,10),0,math.random(5,10))
 end
end

--The whole cycle
while true do
        status.Value = "Choosing Map..."
wait(3)
    choosemap()
    status.Value = "Chosen Map: "..chosenmap.Value
    loadMap()
wait(2)
    status.Value = "Teleporting Players.."
wait(5)
    teleportPlayers()
wait(60)
    deleteMap()
    teleportBack()
end
0
Spawn is probably not in the workspace. By "Infinite yield possible" it means that there is a chance :WaitForChild() will wait forever GoldAngelInDisguise 297 — 5y
0
just put game.Workspace.Spawn tonyv537 95 — 5y
0
this error puzzled me i always thought it was that hack i encountered in a game. The hack was called Infinite yeild imnotacoder 13 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

This is not an error message, it is a warning. It is basically telling you that if the Spawn in the Workspace never loads then the script will wait for it forever. It is just a warning so you don't need to worry much but make sure at some point the spawn is created.

If you want to remove this warning you can put a time limit. That if the spawn doesn't loads in that much time the script will stop waiting for it. Here is the final script:

game.Workspace:WaitForChild("Spawn", 100)

The "100" means that the script will wait for it only 100 seconds if it is not loaded.

I hope this fixes your problem. If it does then don't forget to hit that "Accept Answer" button!

0
exactly starmaq 1290 — 5y
Ad

Answer this question