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

? I keep on getting an error message while trying to change the CFrame of an object

I keep on getting an error message saying ServerScriptService.Spawn/Move:162: attempt to index nil with 'CFrame' when I try to run this code

Name.Focus.CFrame.X = Name.Head.CFrame.X -- The error message is on the first line
Name.Focus.CFrame.Y = Name.Head.CFrame.Y + CFrame.new(0,2,0)
Name.Focus.CFrame.Z = Name.Head.CFrame.Z + CFrame.new(0,0,5)

4 comments

0

A CFrame had ten numbers. It doesn't work like this. Consider watching a youtube tutorial on CFrame as its a bit of a complicated topic to understand.

0

k

0

But shouldn't I be able to just take the x y and z values of CFrame?

0

The positional component of a Coordinate-Frame consists of a Vector3 datatype. You must use one accordingly to adjust the value.

1 answer

✓ Accepted answer

You cannot modify CFrame by it's XYZ values individually. You also cannot add CFrames together, only multiply. When you multiply CFrames, it will add the numbers together. I'll show you some examples and you can go from there

local StartCFrame = CFrame.new(5,5,5)
local DifferenceCFrame = CFrame.new(10,10,10)
-- If you wish to add to any value Individually you must do something like this
local NewCFrame = StartCFrame * CFrame.new(5,0,0)
print(NewCFrame) -- (10,5,5)

local NewCFrame = StartCFrame * CFrame.new(DifferenceCFrame.X,0,0)
print(NewCFrame) -- (15,5,5)

print(StartCFrame * DifferenceCFrame) -- (15,15,15)

local c = CFrame.new(23,5,5) local 
d = CFrame.new(42,10,10) 
print(c*d) -- (65,15,15)


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