hi i was wondering if anyone could help me how to move a player back by a certain amount after touching a part.
this is what i have and it is not working
Part.Touched:Connect(function(hit) if hit.Parent:FindFirstChild:("Humanoid") then local character = hit.Parent character:MoveTo(character.PrimaryPart.Position+Vector3.new(0,0,5) end end)
A CFrame value has a LookVector property that returns the front face of the CFrame value.
You can use this property and multiply this by a number (in studs, whether it be negative or positive), and then increase it by a Vector3 in order to offset the CFrame. It's pretty cool.
Here's an example:
lua
workspace.xd.CFrame = CFrame.new(workspace.xd.CFrame.LookVector*-5 + workspace.xd.Position) * CFrame.Angles(workspace.xd.CFrame:toEulerAnglesXYZ())
--CFrame.Angles to keep the rotation of the part.
You can use this on the HumanoidRootPart to set a player back 5 studs.
Note that using the Position property on the a part breaks all joints related to the part and makes the part fall if not anchored. Do not use this on major body parts such as the head or torso, as this will eliminate the player.