How to make a part tween in front of the player

Hey!
I’m trying to make a part tween from the HumanoidRootPart to 20 studs in front.
I have managed to make the part appear in front of the player correctly, but when I try to tween the position, it goes to a completely different direction.

Here is what happens when I use the tool:
https://gyazo.com/49028c3403b5530a23b24a06f8cdbc41
What is supposed to happen is it goes 20 studs in front of the player, but It seems to always go to this weird fixed location.

Can anyone help me spot the problem if there’s one? Thanks!

Code (regular script activated by a remote event)

local db = false
function activate()
	if db == false then
		db = true
	local part = Instance.new("Part",game.Workspace)
	part.Size = Vector3.new(2,2,2)
	part.Anchored = true
	part.CanCollide = false
	part.Position = script.Parent.Parent.Parent.Parent.HumanoidRootPart.Position + (script.Parent.Parent.Parent.Parent.HumanoidRootPart.CFrame.lookVector * 3)
		local goal = {}
		goal.Position = Vector3.new(script.Parent.Parent.Parent.Parent.HumanoidRootPart.Position + (script.Parent.Parent.Parent.Parent.HumanoidRootPart.CFrame.lookVector * 20))
		goal.Size = Vector3.new(10,10,10)
		local tweenInfo = TweenInfo.new(1)
		local tween = TweenService:Create(part, tweenInfo, goal)
		tween:Play()
		wait(2)
		part:Destroy()
		db = false
		end
	end


script.Parent.OnServerEvent:Connect(function()
	activate()
end)
3 Likes

Unless it all goes in one direction regardless of the way the HumanoidRootPart is facing, try using either:

  • UpVector

  • RightVector

instead of LookVector

2 Likes

I used LookVector because It seemed to work when I spawned the part in front of the player, and
it was in this devforum page.

How would I go about using those different vectors to make the tween go only in the direction the HumanoidRootPart is facing?

local db = false
function activate()
	if db == false then
		db = true
	local part = Instance.new("Part",game.Workspace)
	part.Size = Vector3.new(2,2,2)
	part.Anchored = true
	part.CanCollide = false
	part.Position = script.Parent.Parent.Parent.Parent.HumanoidRootPart.Position + (script.Parent.Parent.Parent.Parent.HumanoidRootPart.CFrame.RightVector * 3)
		local goal = {}
		goal.Position = Vector3.new(script.Parent.Parent.Parent.Parent.HumanoidRootPart.Position + (script.Parent.Parent.Parent.Parent.HumanoidRootPart.CFrame.RightVector * 20))
		goal.Size = Vector3.new(10,10,10)
		local tweenInfo = TweenInfo.new(1)
		local tween = TweenService:Create(part, tweenInfo, goal)
		tween:Play()
		wait(2)
		part:Destroy()
		db = false
		end
	end


script.Parent.OnServerEvent:Connect(function()
	activate()
end)

Yeah, just change it to RightVector or copy this code. Should yield this effect:
https://gyazo.com/6b927c9a8d541dc53111ddba022bafb3

RightVector is like LookVector, but it’s sideways
UpVector is ditto, but upwards instead

1 Like

Rookie mistake, nothing major.
In this example I changed the very long torso reference to just “HumanoidRootPart” for ease of reading (and you should too).

What you’re doing here is assigning all the position math to the X (first) parameter of Vector3.new(). You’re basically doing Vector3.new(Vector3.new(-50, 10, 7.5)) (as an example), which Roblox should tell you doesn’t make sense by throwing an error, but regardless it just gives 0, 0, 0.

image

You should just remove the Vector3.new() entirely and just make it read like:
goal.Position = HumanoidRootPart.Position + (HumanoidRootPart.CFrame.LookVector * 20)

2 Likes

I’m sorry for the delay, was having dinner. I tried that and it gets stuck into one place anyways.

Thanks for the explanation!
Just a quick question, the part is being created at the Handle’s position, how could make it start at the HumanoidRootPart position? (gif from a different angle)

Edit: Nevermind, found it out. Sorry.

Again, shortened torso reference for ease of reading:

part.Position = HumanoidRootPart.Position + (HumanoidRootPart.CFrame.RightVector * 3)

You’re moving the part 3 studs to the right of the torso. Try just setting it to the torso position.

1 Like