Animal Not Spawning in correctly with script

Hello Robloxians, i have come opon a problem with a animal called Ape.
Whenever i try to spawn it through a script instead of it spawning on its feet its spawning in the air sideways.

here is a picture:
image

here is my code:

local AnimalFolder = game.ServerStorage.Animals
local ape = AnimalFolder.Ape

local destroyTime = 600 
local waitDelay = 1


if game.Workspace.Baseplate == nil then
	return
end



local newFolder = Instance.new("Folder")
newFolder.Parent = game.Workspace
newFolder.Name = "Workspace.Ape"

local function CreateNewPart()	
	local NewApe = ape:Clone()

	if not newFolder:IsA("Folder") then 
		return
	end

	NewApe.Parent = newFolder
	local newCFrame = CFrame.new((math.random((-game.Workspace.Baseplate.Size.X / 2), (game.Workspace.Baseplate.Size.X / 2))), 12, (math.random((-game.Workspace.Baseplate.Size.Z / 2), (game.Workspace.Baseplate.Size.Z / 2))))
	NewApe:PivotTo(newCFrame)

	game.Debris:AddItem(NewApe, destroyTime)
end

local amount = 10
local currentAmount = 0

game.Workspace.ChildAdded:Connect(function(child)
	print(child.Name) 
end)

newFolder.ChildRemoved:Connect(function(child)
	if child.Name == ("Ape") then 
		currentAmount = currentAmount - 1
	end
end)

while true do
	if currentAmount < amount then
		currentAmount = currentAmount + 1
		CreateNewPart()
		print(currentAmount)
	end

	if currentAmount == amount then
		print("Ape spawning is at " .. amount .. ". Currently, Ape aren't spawned anymore till Ape is destroyed or deleted.")
	end
	task.wait(waitDelay)
end

does anybody know how to fix this?

It is because of your CFrame. CFrame sets the position AND the angle so that means you just messed up the angle part of it. If you just want to set its position, just set a new position with a Vector3.new() and have the ape facing upwards in serverstorage. Or you could try to fix the miscalculation with the angle but I’m not good with CFrames so i can’t really help u there lol

Ohhh i know why! your comment made me think of the orgin’s orientation in server storage. i had it to i believe. 0, -180, 90 or something. i changed it to 0,0,0 and it works fine now! thank you.

1 Like