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
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?
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.
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.