Hello, I have a platforming game which involves the W,A,D keys to move it left, right, or up. The movement works just fine, but I want to tween it to remove the jerkiness of the cframe. I want to only tween the x and y axis and not the z, but I keep getting the resulting errors such as; "attempt to index field 'cframe' (a nil value)" and "x cannot be assigned to". Here is the script I am using for the tweening:
local cfgoal = {} cfgoal.CFrame = CFrame.new() cfgoal.CFrame.X = newX cfgoal.CFrame.Y = newY local tweeninfo = TweenInfo.new(0.15) local tween = tweenser:Create(workspace.Player, tweeninfo, cfgoal) player.CFrame = CFrame.new(newX,newY,newZ) camera.CFrame = CFrame.new(CameraX,CameraY,newZ + 19.25) print("cur x - ".. cfgoal.CFrame.X) print("cur y - ".. cfgoal.CFrame.Y)
The newX and newY variables are listed above the code. Is there anyway I could possibly tween the x and y axises, and leave the z axis alone?
Also, the line the error comes from is on line 3 of this script.
You can't assign to the X/Y/Z properties of Vector3s and CFrames - you have to manipulate an existing one to accomplish what you want.
If you want to set a CFrame somewhere while respecting its current Z coordinate and angle, you can translate it like so: cf - cf.Position + Vector3.new(goalX, goalY, cf.Position.Z)
To tween this, use the TweenService:GetValue function for full control - you'll have to call it every frame while you're tweening (updating the amount of progress based on the time passed) instead of using TweenService's Create function.