Spawner will not work

I am making a tycoon where fruit spawns every 5 seconds from a random spawn point in a folder from workspace. I keep getting vectore errors and I want to know how I can solve this issue! Thank you for your time.

local SS = game:GetService("ServerStorage")
local spawns = workspace.Tycoon1.AppleTree.AppleSpawns:GetChildren()

local function spawnApple()
	
	local spawnLocation = spawns[math.random(#spawns)]
	
	local apple = Instance.new("Part")
	apple.Name = "apple"
	apple.BrickColor = BrickColor.new("Bright red")
	apple.Size = Vector3.new(1.421, 1.543, 1.489)
	apple.Anchored = false
	
	apple.CFrame = CFrame.new(spawnLocation)
	apple.Parent = workspace
end

while true do 
	spawnApple()
	wait(5)
end

I’ve done something like this before, and in my case I put it like this:

weakDonutClone.Position = cloud.Position

So, in your case it would be like this:

apple.Position = spawnLocation.Position

probably. reply back if it doesn’t work and I can try to help.

Thanks! I was about to try that solution the other day but it didnt show Position on autofill so I thought it would error but it worked!

Because spawns is an array of descendants (the type of the returned value from :GetChildren()), spawnLocation is an Instance rather than a Vector3 value. In hindsight, you’re essentially doing:

CFrame.new(<Instance>)

when you should be doing

CFrame.new(<Vector3>)

The most obvious way to solve this would be to read the instance’s position rather than passing it directly:

CFrame.new(spawnLocation.Position)

or rather just set the CFrame directly:

apple.CFrame = spawnLocation.CFrame

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.