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
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: