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

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

Asked by
Minifig77 190
10 years ago

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?

Locked by TheMyrco

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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

Ad