Attempted to index number with position

I got the error at line 15 I think and I spent a while trying different things to fix it but just can’t figure it out, how do I fix it?

local m = game.ServerStorage.Clones.Noob:Clone()

local s1 = game.Workspace.EnemySpawns.s1
local s2 = game.Workspace.EnemySpawns.s2
local s3 = game.Workspace.EnemySpawns.s3
local s4 = game.Workspace.EnemySpawns.s4
local s5 = game.Workspace.EnemySpawns.s5
local spawns = {s1, s2, s3 ,s4, s5}

while true do
	local pos = math.random(1, #spawns)
	wait(2)
	local cloned = m:clone()
	cloned.Parent = script.Parent
	cloned.HumanoidRootPart.CFrame = CFrame.new(pos.Position)
	cloned:makeJoints()
end

you are attempting to apply a random number as a CFrame
plus, a number doesn’t have a Position

I was originally using another method where it just used one spawn and the spawn’s position but I wanted to add random enemy spawns, and then it broke, how do I fix it?

So basically I have a folder with 5 spawns and it picks a random one, the enemy would just move to the one that is picked, would this work?

if you want to get a random entry from the table you should do this instead

local pos = spawns[math.random(1, #spawns)]

This will refernce the actual instance rather then referencing the random number the first line choose

oh my god i’m an idiot thank you

1 Like

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