Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Doesn't a Model have a CFrame like any Part?

Hey all!

I'm new to cameras and I'm trying to make a camera script that circles around a model when a player enters the game (and a one-time GUI). I got this error for a camera script:

16:46:04.260 - CFrame is not a valid member of Model 16:46:04.260 - Stack Begin 16:46:04.261 - Script 'Players.Player1.PlayerGui.ScreenGui.TextButton.ButtonScript', Line 17 16:46:04.261 - Stack End

Here's Line 17 (full script at the end) :

cam.CoordinateFrame = workspace.Castle.CFrame * CFrame.Angles(0,angle,0)

Castle is a model made up of 2 models (Basically 2 models grouped together)

On the Wiki, CFrame is a valid property of Model, so what is this error trying to tell me?

FULL SCRIPT

workspace:WaitForChild("Castle")
cam = workspace.CurrentCamera
rotate = true
player = game.Players.LocalPlayer
loaded = false
script.Parent.MouseButton1Click:connect(function()
	if loaded then
		rotate = false
		cam.CameraSubject = player.Character.Humanoid
		cam.CameraType = "Follow"
		script.Parent.Parent:Destroy()
	end
end)
cam.CameraSubject = workspace.Castle
angle = 0
while rotate do
	cam.CoordinateFrame = workspace.Castle.CFrame * CFrame.Angles(0,angle,0)
	angle = angle + math.rad(3)
	if player.Character:FindFirstChild("Humanoid") then
		loaded = true
	end
	wait()
end

1 answer

✓ Accepted answer

A model can have multiple parts all of which will have their own CFrame, it does have a PrimaryPart which can be set. This part will then act as the central point for the model.You can access the primary part or use the functions of the model class to manipulate the whole model.

Back to your question, there is a function GetPrimaryPartCFrame which returns the CFrame of the primary part, note this will error one is not set.

You can set the primary part in the properties of the model in studio so this does not need to be set via a script, but you can also change the primary part if needed.

Example:-

cam.CoordinateFrame = workspace.Castle:GetPrimaryPartCFrame() * CFrame.Angles(0,angle,0)

I hope this help.

1 comment

0

Thanks for that, I'll test it out and accept it as the correct answer if it works out. While I'm at it, the script up there should work right?

This discussion is preserved as it was. New answers, comments, and votes are closed.