Hey, I’m trying to point an object in a certain direction, three studs in front of my player to be specific, so it can move in front of them. But no matter what I change in (what I think is) argument two, it gives me the same error. arm["Right Arm"].CFrame = CFrame.new(arm["Right Arm"].CFrame:ToWorldSpace(Vector3.new(0,0,-1)),arm["Right Arm"].CFrame.LookVector) is the code that’s been giving me issues.
Now I know there might be similar topics, but what differentiates this one from the others is:
Argument 2 is arm[“Right Arm”].CFrame.LookVector. It is a Vector3, not a CFrame, just use:
CFrame.new(arm[“Right Arm”].CFrame.LookVector) I think. That’ll convert it to a CFrame.\
The issue is in ToWorldSpace. It takes in a CFrame, not a Vector3.
Another issue would be that CFrame.new does not accept a CFrame at all for it’s arguments. ToWorldSpace returns a CFrame so you’d have to get the position of it.
Solving this probably won’t achieve what you want, but at least you won’t have errors.
Argument 2 means second thing in the brackets, that may be an error of itself. I don’t think the : is erroring.
The ToWorldSpace might be another error. But I do not believe it is the case here.
The only thing that has 2 arguments here is the CFrame.new constructor.
But you are right, that’s another thing that needs to be fixed.
Do you know how : works in relation to class methods? The code never reaches the second argument of his CFrame.new because it crashes at the incorrect usage of ToWorldSpace.
I understand if you two are confused because the error output is misleading, this is probably ROBLOX’s fault. Not sure how they ought to do different error output based on if you use the syntax sugar for class methods.
It doesn’t necessarily stop by the order AFAIK and understand, but I might be wrong.
Lua is an interpreted language meaning it runs line by line. Java is a compiled language, which reads the entire file and then creates code you can run. So when it was compiling, it “crashed” on the type error. Not sure if Java’s compiler checks for out of bounds access in arrays.
the error in the code is caused by using vector3 instead of a cframe on CFrame:ToWorldSpace(CFrame) like Hamster said above
arm[“Right Arm”].CFrame = CFrame.new(arm[“Right Arm”].CFrame:ToWorldSpace(CFrame.new(0,0,-1)),arm[“Right Arm”].CFrame.LookVector) – changing it to a cframe
An easier way of doing this for your use I think would be something like this:
Part.CFrame = arm.CFrame – this gives it the same cframe rotation of the arm
Part.Position = arm.Position + (arm.CFrame.LookVector* 5) – this moves it 5 studs infrom of the arms lookvector
or with 1 line:
Part.CFrame = (arm.CFrame - arm.Position) + (arm.Position + (arm.CFrame.LookVector* 5))
CFrame:ToWorldSpace() takes a CFrame and returns a CFrame, CFrame:PointToWorldSpace() takes a Vector3 and returns a Vector3.
Also second argument of CFrame.new() takes the Vector3 you should be looking at and not the look direction (LookVector), so here is a fix arm["Right Arm"].CFrame = arm["Right Arm"].CFrame:ToWorldSpace(CFrame.new(Vector3.new(0, 0, -1), arm["Right Arm"].CFrame.LookVector))
also this method will keep on moving the arm infinitely forwards as you keep incrementing it, why do you want the hand to be moving forwards?
Okay, finally! Thank you! This finally makes the effect working properly, but I now need the effects pointing at a very specific location. How do you think I can achieve this?