Why this script doesn't work?

So I was practicing on how to move the player when a key is activated (move the Z axis a bit) but first I tried it with a part but:

local part = script.Parent 
local antcframe = part.CFrame.Z
wait(20) 
print("listoooooooooo")
part.CFrame.Z = antcframe + CFrame.new(CFrame.new(013.831 ) )

It didn’t work and I tried it with VectorZ even but nothing works please help me

Your CFrame.new has invalid syntax, CFrame.new() takes a single Vector3 as an input, and a Vector3 takes 3 numbers as an input, also, you cannot set the Z value of a CFrame’s position, also, to read the position of a CFrame you need to do part.CFrame.Position.

Making this particular script work should be as easy as changing

part.CFrame.Z = antcframe + CFrame.new(CFrame.new(013.831 ) )

to

part.CFrame = antcframe+CFrame.new(Vector3.new(0,0,13.831))

And maybe decreasing that wait(20) so you don’t have to wait 20 seconds every time you try to test it.

Have you checked the output. There has to be some kind of error indicating what isn’t working.

It doesn’t seem to work with the changes:

local part = game.Workspace.part
local antcframe = part.CFrame
wait(5) 
print("listoooooooooo")

part.CFrame = antcframe+CFrame.new(Vector3.new(0,0,13.831))

It tells me in the output that I should remove the CFrame and put a vector in its place but it still doesn’t work

local part = game.Workspace.part
local antcframe = part.CFrame.Z
wait(5) 
print("listoooooooooo")

part.CFrame = CFrame.new(Vector3.new(0,0,13.831 + antcframe))

I’m not positive this will work but I think it should. If not let me know (I think your issue was you were adding a Z of a Vector3 to a CFrame)

It didn’t work for me but I did something similar that did work for me:

local part = game.Workspace.part
local antcframe = part.CFrame
wait(5) 
print("listoooooooooo")

part.CFrame = antcframe + CFrame.new(0,0,017.123)

But now I need to know how to add the Z axis frontally, since if the part (HumanoidRootPart) is from another angle then it goes backwards or I don’t know but what I do know is that it doesn’t work for me if you know how please

Use multiplication instead of addition to have it be based on where the part is facing

would be this: *?
And how more or less would I do it and how does it work?

Yes it would be *

When you multiply CFrames it moves based on the rotation. So

HumanoidRootPart.CFrame * CFrame.new(0,0,-10) 

Would move the player 10 studs away from where they are facing

1 Like

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