Move HumanoidRootPart with Vector3

My HumanoidRootPart can’t move with Vector3.
How can i make HumanoidRootPart move?

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local UIS = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
local humanoid = Character:WaitForChild("Humanoid")
local humanoidrp = Character:WaitForChild("HumanoidRootPart")
local ti = TweenInfo.new(

	0.5,
	Enum.EasingStyle.Sine


)

UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
	if input.KeyCode == Enum.KeyCode.E then
		local Anim = Instance.new('Animation')
		Anim.AnimationId = 'rbxassetid://16488920677'
		PlayAnim = Character.Humanoid:LoadAnimation(Anim)
		PlayAnim:Play()
		tweenService:Create(humanoid, ti, {CFrame = humanoidrp.CFrame + Vector3.new(5, 0, 0)}):Play()
	end
end)	

UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		PlayAnim:Stop()
	end
end)

CFrame and Vector3 are two different data types.

tweenService:Create(humanoid, ti, {Position = humanoidrp.CFrame.Position + Vector3.new(5, 0, 0)}):Play()

I’d just add .Position to get CFrame 3D position.

2 Likes

You can actually add a Vector3 onto a CFrame but not the other way around.

This works:
CFrame + Vector3 = CFrame

This doesn’t work;
Vector3 + CFrame


They’re tweening the ‘humanoid’ and not the humanoid root part:
tweenService:Create(humanoid, ti, {CFrame = humanoidrp.CFrame + Vector3.new(5, 0, 0)}):Play()

Uses RootPart:
tweenService:Create(humanoidrp, ti, {CFrame = humanoidrp.CFrame + Vector3.new(5, 0, 0)}):Play()

humanoidrp and not humanoid… you cant change CFrame of humanoid

1 Like

Thank you very much for fixing my error!

What to do if player moves only in one direction, not in right?
like this:
robloxapp-20240224-1354241.wmv (1.3 MB)

Atm you have it set to one direction, so if you wanted to have it go in left/right relative to the root part then use the root part’s cframe to your advantage.

Like:

local direction = rootPart.CFrame.RightVector
local distance = 5

-- // left is -direction || forward is lookvector || backwards is -lookvector

tweenService:Create(rootPart, ti, {CFrame = rootPart.CFrame + direction * distance}):Play()
1 Like

the result is the same. for some reason it still goes in one direction without relation to RootPart

Since the CFrame always changes you’ll be creating the variable within the same function that you have the tween called in.

1 Like

yeah for future, please, attach error messages.

1 Like

i found how to fix this problem.
CFrame needs to multiply with CFrame.new()
like this:

CFrame = humanoidrp.CFrame * CFrame.new(-3, 0, 0)

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