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)
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)
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.
You should just remove the Vector3.new() entirely and just make it read like: goal.Position = HumanoidRootPart.Position + (HumanoidRootPart.CFrame.LookVector * 20)
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)