Help With this spawning System

local Tree1 = game.ReplicatedStorage.TreeFolder.Tree1
local TreeS = game.Workspace.TreeSpawner
while true do
wait()
end
if TreeS.Reflectance == 1 then
Tree1.Parent = game.Workspace
Tree1.Position = Vector3.new(0, 0, 0)

elseif TreeS.Reflectance == 0 then wait(20)

end
TreeS is a part child of the workspace and the point where i want my Tree1 to spawn

1 Like

I think you should format your code first. It’s very messy too, I can’t understand it.

In addition to what AndriodBoyz said, could you please elaborate on the question a bit? I am not really sure what I am looking at, do you want it to spawn a new tree at a certain position or what is it that you are trying to achieve?

why do you have an infinite wait? The wait does nothing other than slightly lag.
From what I can see, (of course, I can’t understand the formatting or the question well), here it is

local Tree1 = game.ReplicatedStorage.TreeFolder.Tree1
local TreeS = game.Workspace.TreeSpawner
while wait() do

if TreeS.Reflectance == 1 then
Tree1.Parent = game.Workspace
Tree1.Position = Vector3.new(0, 0, 0)

elseif TreeS.Reflectance == 0 then wait(20)
end
end

All you had was an end in the wrong place which caused the if to never run

1 Like

If your problem is that it won’t spawn, it’s probably because of the while loop you placed in front of it. Having an infinite loop in front of any code will make the code after never run, hence making it useless. This is exactly what’s happening in your code. Here’s a snippet that might solve your problem.

local Tree1 = game.ReplicatedStorage.TreeFolder.Tree1
local TreeS = game.Workspace.TreeSpawner
while wait() do
    if TreeS.Reflectance == 1 then
        Tree1.Parent = game.Workspace
        Tree1.Position = Vector3.new(0, 0, 0)

    elseif TreeS.Reflectance == 0 then 
        wait(20)
    end
end