Hi, what I'm trying to do here is spawn an object named "Foil" to workspace. The "Foil" is in a "Model" named Loot. The script is trying to identify if there is a object named "Foil" in workspace and if there is, then the script won't work. If there is no Foil in workspace, the "Foil" will spawn into the workspace, and move to a part's position.
Material = game.Lighting.Loot:getChildren()
Foil = game.workspace:findFirstChild("Foil")
function Spawning()
for i = 1, #Material do
if Material[i] and Material[i]:findFirstChild("Foil") then
if Foil.Parent ~= game.workspace then
local Materials = Material[i]["Foil"]:Clone()
Materials.Parent = workspace
local Part = game.Workspace.Part
if Part ~= nil then
Materials:MoveTo(Part.Position)
end
elseif Foil.Parent == workspace then
local p = nil
return p
end
end
end
end
while true do
wait(1)
print("Spawning")
Spawning()
end

2 comments
Thanks for explaining, I'll check it out
Alright. If something doesn't work tell me and I'll try it.