CFrame is not a valid member of model error

I’m getting an error every time I run this code does anyone know why?
I am trying to get a random zombie from a folder to spawn at a random spawn location.
Error: CFrame is not a valid member of Model
Server script Inside ServerScriptService:

 while true do
--// SpawnPoints + Random Spawn Point
local SpawnPoints = workspace.SpawnPoints:GetChildren()
local NumberOfSpawnPoints = #SpawnPoints
local RSP = math.random(1, NumberOfSpawnPoints)
local ChosenSpawnPoint = SpawnPoints[RSP]

--// Replicated Storage
local RS = game:GetService("ReplicatedStorage")

--// Zombies + Random Zombie
local Zombies = RS:WaitForChild("Zombies"):GetChildren()
local NumberOfZombies = #Zombies
local RZ = math.random(1, NumberOfZombies)
local ChosenZombie = Zombies[RZ]

	
--// Cloned Random Zombie
local ClonedZombie = ChosenZombie:Clone()

	ClonedZombie.Parent = ChosenSpawnPoint
	ClonedZombie.CFrame = ChosenSpawnPoint.CFrame
	wait(5)
end
1 Like

Which line is it on? It’s always helpful to be able to see the full output and stack trace.
Your script is pretty short though, at a glance I’d assume it’s this line here

ClonedZombie.CFrame = ChosenSpawnPoint.CFrame

Models don’t have CFrames. Do you have any Models in SpawnPoints?

2 Likes

Yes, line 22. The spawn point is a part inside of a folder in the workspace and the zombies are in a folder inside of replicated storage. I don’t know what this error is trying to tell me because the spawn point is a part.

1 Like

If it’s an actual model class, then you need to do this instead:

--// Cloned Random Zombie
local ClonedZombie = ChosenZombie:Clone()

	ClonedZombie.Parent = ChosenSpawnPoint
	ClonedZombie:PivotTo(ChosenSpawnPoint.CFrame)
	wait(5)
end

Alternatively, you can use Model:MoveTo(Position) to move to a position represented as a Vector3.

3 Likes

Thanks, will try this tomorrow to see if it works then I will update your comment to be marked as the solution.

I think its ClonedZombie:PivotTo(ChosenSpawnPoint.CFrame) not ClonedZombie.PivotTo(ChosenSpawnPoint.CFrame)

1 Like

No.

Model:PivotTo is a method, not a property. Therefore the form that I used is correct. Using a period instead of a colon will throw an error.

1 Like

??? You wrote ClonedZombie.PivotTo(ChosenSpawnPoint.CFrame), which is wrong, because self is not passed.

You would call it with

ClonedZombie:PivotTo(ChosenSpawnPoint.CFrame)
-- equivalent to
ClonedZombie.PivotTo(ClonedZombie, ChosenSpawnPoint.CFrame)
1 Like

CFrame is not a property of models, instead, u can use:

local cframe = model.PrimaryPart.CFrame
-- or
local cframe, size = model:GetBoundingBox()
2 Likes

I guess I did. Corrected. I’ve made that mistake a number of times. Thanks for pointing that out.

1 Like

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