Infinite yield possible on 'Workspace:WaitForChild("Spawner3")'

(Yes, I’m aware this script is very unoptimized.)

Basically, I’ve done a script which randomizes spawns, well lets say it didn’t work.

Basically, when doing it I stumbled across a warning which says the part doesn’t exist. I’ve checked the name hundreds of times, still no clue why this happened. I’ve also cloned the script and inserted it into workspace, still no clue.


while true do
	wait(3)
	local num = math.random(1 ,3)
	if num == 1 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = workspace:WaitForChild("Spawner1").Position
		c.Parent = workspace
	elseif num == 2 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = workspace:WaitForChild("Spawner2").Position
		c.Parent = workspace		
	elseif num == 3 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = workspace:WaitForChild("Spawner3").Position
		c.Parent = workspace
	end
end

image
image
image(by the way this is happening to all 3 spawners)

And yes, I will optimize this later.

1 Like

1- For me it works completely fine.
2- There is no need to use WaitForChild in this case
3-Use task.wait() instead of wait.

Try this :

while true do
	task.wait(3)
	local num = math.random(1 ,3)
	if num == 1 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = workspace.Spawner1.Position
		c.Parent = workspace
	elseif num == 2 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = workspace.Spawner2.Position
		c.Parent = workspace		
	elseif num == 3 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = workspace.Spawner3.Position
		c.Parent = workspace
	end
end
1 Like

I completely forgot about task.wait(), just slipped out of my mind.

1 Like


same thing, didn’t work at all…

1 Like

Show me your workspace please [relevant items]

1 Like

image

1 Like

Oh, I found the issue ,
it’s because the low case workspace.

You can do either of these ways :

1- change it to Workspace
2- do game.workspace

while true do
	task.wait(3)
	local num = math.random(1 ,3)
	if num == 1 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = Workspace.Spawner1.Position
		c.Parent = workspace
	elseif num == 2 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = Workspace.Spawner2.Position
		c.Parent = workspace		
	elseif num == 3 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = Workspace.Spawner3.Position
		c.Parent = workspace
	end
end
1 Like

Try now, and tell me if any error occurs


i have no idea whats going on:

while true do
	task.wait(3)
	local num = math.random(1 ,3)
	if num == 1 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = game.Workspace.Spawner1.Position
		c.Parent = game.Workspace
	elseif num == 2 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = game.Workspace.Spawner2.Position
		c.Parent = game.Workspace		
	elseif num == 3 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = game.Workspace.Position
		c.Parent = game.Workspace
	end
	end
1 Like

Workspace is deprecated, workspace is the thing you should use.

Already used that, failed as well.

1 Like

Your doing game.Workspace.Position , Maybe thats the problem?

Not using game.workspace.Position.

1 Like

You sure? Check again. Its on the 3rd if statement.

local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = game.Workspace.Position
		c.Parent = game.Workspace
1 Like

I’m using this now:

while true do
	task.wait(3)
	local num = math.random(1 ,3)
	if num == 1 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = game.Workspace:WaitForChild("Spawner1").Position
		c.Parent = game.Workspace
	elseif num == 2 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = game.Workspace:WaitForChild("Spawner2").Position
		c.Parent = game.Workspace		
	elseif num == 3 then
		local c = game.ReplicatedStorage.Tool:Clone()
		c.Handle.Position = game.Workspace:WaitForChild("Spawner3").Position
		c.Parent = game.Workspace
	end
	end

Are the spawners unachored? If so, it could be falling into the void. Is there anything else that could delete it?

1 Like

Deprecated ~= not working, I’ve been told that already

Im just saying using “Workspace” instead of “workspace” is not gonna make a difference.

2 Likes

Thanks so much, that worked absolutely right.

3 Likes