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

How do I make a new instance have a certain rotation?

Asked by 9 years ago

I want a script to spawn a new part (got that down) and give it the rotation of the body part it is spawned from. I've sorta got parts of it, so here is some of it:

fh.BrickColor = BrickColor.new("Bright yellow")
    fh.CFrame = CFrame.new(script.Parent.Parent.Character:FindFirstChild("Head").Position.X,script.Parent.Parent.Character:FindFirstChild("Head").Position.Y-0,script.Parent.Parent.Character:FindFirstChild("Head").Position.Z)--Edited
    fh.Rotation = Rotation.new(script.Parent.Parent.Character:FindFirstChild("Head").Rotation.X,script.Parent.Parent.Character:FindFirstChild("Head").Rotation.Y-0,script.Parent.Parent.Character:FindFirstChild("Head").Rotation.Z)
    game.Debris:AddItem(fh,0.8)

(P.S. There may be an indentation missing but that doesn't matter, I just need the parts rotation to be similar to that of the body part.)

2 answers

Log in to vote
0
Answered by 9 years ago

You can set the CFrame to the head's CFrame and it will give it the same position and rotation of the head object, for example:

fh.CFrame = script.Parent.Parent.Character:FindFirstChild("Head").CFrame

This will get the CFrame of the characters head, which contains the position and rotation of it, and set it to the part 'fh'

0
The bearded man has done it again... Xianon 105 — 9y
Ad
Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Well I don't quite understand what your code is doing.. but to match a new part's rotation with a predefined part's rotation then you just need to make the new part's CFrame equivelant to that of the predefined part.

local old = workspace.Part --Old part
local new = Instance.new('Part',workspace) --New part.

new.CFrame = old.CFrame --Match CFrames, equivelant rotation

In your case, you're wanting to match fh's CFrame with script.Parent.Parent.Character:FindFirstChild("Head")'s CFrame..

fh.CFrame = script.Parent.Parent.Character:FindFirstChild("Head").CFrame

Answer this question