I'd like to start experimenting with cframe, but I have no clue where to start. I've looked at wiki's, and many tutorials. Although they all seem to be outdated, or make no sense to me. I've also studied other scripts that use cframe to animate players, although they were much too advanced for me. Could anyone link me to a useful article or tutorial, or if you have the time, explain how I can move/animate parts of a player using cframe.
(More specifically I would like to learn how to move a part from its existing position to another position in accordance to its current position. Such as rotating a part and moving it several units up from its current position.)
Any help would be much appreciated, thank you.
First, you would need to look and wait for the player to spawn or to "exist".
So, to do that you would need to use WaitForChild()
.
The most common mistake that people make is using FindFirstChild()
and end up not getting the script to work because the character didn't exist yet.
This is one of my scripts and I'm gonna show it as an example: Also, check if the part exists.
function getPlayer(player) if player and player.Character then local humanoidRootPart = player.Character:WaitForChild("HumanoidRootPart") if humanoidRootPart then -- Checking if it exists, extra safe. -- Nothing yet end end end
After waiting for that specific part, you would then use CFrame to properly teleport the Player. ( Not killing them ). So to do that you would do this:
local baseplate = game.Workspace.Baseplate humanoidRootPart.CFrame = CFrame.new(baseplate.Position + Vector3.new(0,3,0))
Becareful when using CFrame, since it will teleport to the exact position you tell it to, so if there's a floor. The player will end up getting stuck in the floor. So add like a bit of Y value like I did.
CFrame lets you teleport a part and whatever is attached to the part that you teleported, will follow the part as well. Hope this helped.