I’m making a cooking system, and this specific part is where the character is chopping something. Its goal is to position the camera at a certain point, specified by a parts position, and be pointed at the area where the player is chopping. All of this works just fine, UNTIL where the part you are supposed to jump to stop the process, this below happens:
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local part = workspace.ChoppingStation.ChoppingPosition
local animationId = "rbxassetid://15659800824"
local animation = Instance.new("Animation")
animation.AnimationId = animationId
local animationTrack = humanoid:LoadAnimation(animation)
part.Touched:Connect(function(hit)
if hit.Parent == player.Character then
humanoid.WalkSpeed = 0
animationTrack:Play()
local camera = workspace.CurrentCamera
local headPosition = char.Head.Position
local targetPosition = headPosition + Vector3.new(0, 3, 0)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.Parent.Camera.CFrame
char.HumanoidRootPart.Position = part.Position
local jumpListener
jumpListener = humanoid.Jumping:Connect(function(IsJumping)
if IsJumping then
RunService.Heartbeat:Wait(1)
camera.CFrame = char.HumanoidRootPart.CFrame
camera.CameraType = Enum.CameraType.Custom
local offset = part.CFrame:PointToWorldSpace(Vector3.new(0, 0, 5))
char:SetPrimaryPartCFrame(CFrame.new(offset))
humanoid.WalkSpeed = 16
jumpListener:Disconnect()
animationTrack:Stop()
end
end)
end
end)
I think this has something to do with char.HumanoidRootPart.Position = part.Position, but my attempts to edit it to be somewhere else produce the same result.
An offset means you’re transforming from A by B. Doing CFrame.new(), however, is creating a fresh CFrame. When you plug in an offset, it doesn’t work as intended.
You need to set the CFrame to the current CFrame plus the offset.