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

[ANSWERED] How come CFrame values set as variables are Userdata?

I'm programming a nuclear missile with an accurate flight path. To do so, I have to have several points as variables that are the locations of different flight stages (e.g. Where the main thruster kicks in, or where the warhead detaches from the rocket and flies to the ground.) I set the variables in the code, and whenever the destination is set in the code, the rest of the coordinates in the flight path are calculated. The problem is whenever I try to do something like this:

CentralThruster = script.Parent.Parent.Rocket.Propulsion.Thrusters.CentralThruster.Glow.CFrame
BlastPoint = CFrame.new(CentralThruster.X, CentralThruster.Y+238, CentralThruster.Z)
script.Parent.Guide1.BodyPosition.position = BlastPoint

Whenever I run the code, the output reads, "Workspace.Missile.Warhead.LaunchScript:31: bad argument #3 to 'position' (Vector3 expected, got userdata)"

So, I do:

CentralThruster = script.Parent.Parent.Rocket.Propulsion.Thrusters.CentralThruster.Glow.CFrame
BlastPoint = CFrame.new(CentralThruster.X, CentralThruster.Y+238, CentralThruster.Z)
script.Parent.Guide1.BodyPosition.position = Vector3.new(BlastPoint) --Change in this line.

As it turns out, Vector3.new of any CFrame value is "0, 0, 0," which means that my rocket doesn't do anything.

I tried some other creative solutions, all of which ended up in errors.

How do I set the BodyPosition's position to the BlastPoint variable in the code without an error?

1 answer

✓ Accepted answer

CFrames are not Vector3s. You are setting position to BlastPoint, but position is a Vector3 and BlastPoint is a CFrame. You need to get the position of BlastPoint by using its p property (which is a Vector3):

script.Parent.Guide1.BodyPosition.position = BlastPoint.p

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