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

What is CFrame and how would I use it in my games?

CFrame is used in alot of scripts and I have no idea what it is, how to use it, or even what it is used for. Please help.

3 answers

✓ Accepted answer

CFrame is very simply a database containing both position and orientation. There are loads of uses for CFrame such as creating beams from raycasting, rotating parts, and even teleporting players. I'll show you some examples below. (Note: I will be putting the things in --comments.) for moving parts alone, I just recommend you use Vector3.

Rotating the part's orientation

local part = workspace.Part

part.CFrame = CFrame.Angles(0,math.rad(90),0) --This changes the angle of the part, however, it resets the position to 0,0,0. So you need to do something like this:

part.CFrame = part.CFrame * CFrame.Angles(0,math.rad(90),0) --using the * is like adding.

Teleporting the player to another part (Not to be confused with TeleportService)

local part = workspace.Part

for i, v in pairs(game.Players:GetPlayers()) do --This gets the players.
	local character = v.Character
	character.HumanoidRootPart = part.CFrame --This teleports the player to the part, however, make sure collision is off and the part is transparent. If you use typical Vector3, it would instantly kill the player.
end

4 comments

0

Where did you learn how to script lol

0

Devking.

0

Ooh your so good!

0

Thank you.

CFrame is an objects position and orientation in the workspace. You would use it to move a part (or model) , locate parts etc.

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