Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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
0
Where did you learn how to script lol iivSnooxy 248 — 3y
0
Devking. Dovydas1118 1495 — 3y
0
Ooh your so good! iivSnooxy 248 — 3y
0
Thank you. Dovydas1118 1495 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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

Log in to vote
0
Answered by
iivSnooxy 248 Moderation Voter
3 years ago

Heyyy, maybe you could refer to some of these recourses:)

https://www.youtube.com/watch?v=VxgNleUdmmg https://www.youtube.com/watch?v=9YqN8_VERps

0
I think you should explain CFrame, instead of linking a YT video. You can link the video along with your answer. Dovydas1118 1495 — 3y
0
Kk thx iivSnooxy 248 — 3y

Answer this question