Need help with character elevating off the ground and going in random positions variously?

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:

This has me laughing for minutes on end!

Here’s the script lol:

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.

Help is appreciated, thanks for reading!

1 Like

image
:rofl::rofl::rofl::rofl:

1 Like

image

1 Like


I’m cryingggggg :sob::sob::sob::sob::sob:


She sees you when you’re sleeping, she knows when you’re awake.

1 Like

Are there any possibilities to provide a video of what happens instead of only pictures? Just so others can understand the behavior deeply.

1 Like
local offset = part.CFrame:PointToWorldSpace(Vector3.new(0, 0, 5))

This is the same as part.CFrame * Vector3.new(0,0,5). You’re copying the CFrame of part, so you’ll be oriented similarly.

1 Like

Are you anchoring the humanoid root part ?

1 Like

robloxapp-20231217-1008467.wmv (4.5 MB)

This makes sense to me, and I just set it to position instead:

local offset = part.Position - Vector3.new(0,0,5)
char:SetPrimaryPartCFrame(CFrame.new(offset))

However, the same effect is happening.

I am not.

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.

1 Like

Just so I understand this correctly, something like this?

local offset = char.HumanoidRootPart.CFrame - Vector3.new(0,0,5)
char:SetPrimaryPartCFrame(offset)

Sort of. More like this.

local offset = Vector3.new(0,5,0)
local origin = char.PrimaryPart.CFrame
char:SetPrimaryPartCFrame(origin+offset)

The same result is produced. The animation track includes tilting the torso, do you thing that could be an issue since it’s stopping it abruptly?

Probably. Why don’t you pause the animation and see if it works?

Looks like that was the case:
image

Well, you can do AnimationTrack:Pause().

But when I debug something I tend to comment out the code that I want to exclude

It looks like that was the case, how would I return the player to the OG state?

If you did it like this,

local offset = Vector3.new(0,5,0)
local origin = char.PrimaryPart.CFrame
char:SetPrimaryPartCFrame(origin+offset)

then origin is still the original CFrame. So you can just set it to origin.

Unfortunately this hasn’t worked either. I’ll try creating a separate animation where nothing moves and playing that instead.

Anchoring the HumanoidRootPart should fix the problem

I tried it out, and it mutes the jumping detection.