Unable to cast CoordinateFrame to float

The line

EnemiesActive:WaitForChild(EnemyID).PrimaryPart.CFrame = CFrame.new(Position) * CFrame.fromOrientation(LookPositionX, LookPositionY, 0)

Position, LookpositionX and lookpositionY are both floats, so i dont know why there is an error

1 Like

You can’t construct a CFrame like this. It is not a valid constructor. LookPositionX and LookPositionY need to be float values, which it described in the error.

There is no CFrame.new(CFrame, CFrame, Float) constructor, and the engine tried to resolve this by casting your first two parameters to a Float, which it can’t because there is no sensible way to do it.

What exactly are LookPositionX and LookPositionY.

If you are trying to make the enemy look at something, you can do:

PrimaryPart.CFrame = CFrame.lookAt(PrimaryPart.Position, LookAtPosition)

Where LookAtPosition is in WorldSpace

3 Likes

What do you mean its not a valid constructor: LookPositionX and Y are both floats. It works for some models just not for this one and im not sure why?

2 Likes

You said in your OP that they are CFrames. In the error message, it also appears you are trying to pass a CFrame to a float.

By “valid constructor” I mean that CFrame.new offers many ways to create a CoordinateFrame, but the way you’re doing it is not one of them.

2 Likes

oh im so sorry my bad. Ill change it. They are both floats though

2 Likes

this is how they are made.

LookPositionX, LookPositionY = CFrame.new(Position, QuadraticBezier(Time + 0.001, Node0, Node1, Node2)):ToOrientation()
2 Likes

:ToOrientation returns angles in Z, Y, X order by the way, not X, Y, Z

Is the structure for this model different?

2 Likes

its just an arrow, one mesh part,

:ToOrientation returns angles in Z, Y, X order by the way, not X, Y, Z

also it works perfectly fine its just how i name the variables. It makes me understand them easier, as from orientation needs them in z, y, x order

Here is an image
image

1 Like

Print the types of each variable before you create the new CFrame, or wherever it is erroring. I assume its erroring where you made the code in the OP.

print(typeof(LookPositionX), typeof(LookPositionY), typeof(0))
EnemiesActive:WaitForChild(EnemyID).PrimaryPart.CFrame = CFrame.new(Position) * CFrame.fromOrientation(LookPositionX, LookPositionY, 0)

Ideally it says number number number and the code does not error

2 Likes

this is what i wrote

print(typeof(LookPositionX), typeof(LookPositionY), typeof(0), typeof(Position))

this is what outputs
number number number Vector3

1 Like

And its erroring with “Unable to cast CoordinateFrame to float”?

I wanted you to print the types where and when it is erroring.

2 Likes

that’s all it is, all the values. That’s why I’m confused with such a small error.

what other values should i print

EnemiesActive:WaitForChild(EnemyID).PrimaryPart.CFrame = CFrame.new(Position) * CFrame.fromOrientation(LookPositionX, LookPositionY, 0)
1 Like

figured it out, was just because of some weird look position x changing. Thanks though

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.