First off, sorry if the solution is quite simple. I haven’t done any luau in about a year, so I am definitely not competent.
Anyway…
So I am working on a retractable sword (details are not important), and my method of making this happen is 2 tweens. The first one adjusts the size of the sword blade to be right and then the second tween one moves the blade to make up for the first tween making the blade grow in both directions. There is an issue here though, since I am using vector3 for the second tween (does not matter for the first one as far as I know), the blade only is in the correct place if i am facing in the correct axis. I tried using cframe for it because that seemed to be the correct solution, but I think I was wrong as that was flat out not working…
To be honest I have no idea if using 2 tweens is even right for this. Not knowing if I am even in the ballpark of “correct” is not fun, so that’s part of why I am asking here. Thank you in advance
Here is a video of the issue, the blade moving is me pressing E (I need to have a retract, just ignore that part)
Lastly, the code (don’t roast me too hard):
local player = game.Players.LocalPlayer
local userInputService = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
local contextActionService = game:GetService("ContextActionService")
local playTweensEvent = game.ReplicatedStorage:WaitForChild("PlayTweensEvent")
local blade = script.Parent.Blade
local handle = script.Parent.Handle
-- function to create the tweens
local function createTweens()
local animTime = .15
local easingStyle = Enum.EasingStyle.Linear
local easingDirection = Enum.EasingDirection.InOut
local tweenInfo = TweenInfo.new(animTime, easingStyle, easingDirection)
-- Tween1: change blade size
local goal1 = {Size = Vector3.new(4.5, 0.25, 0.25)}
local tween1 = tweenService:Create(blade, tweenInfo, goal1)
-- Tween2: move the blade
local goal2 = {Position = handle.Position + Vector3.new(2.25, 0, 0)}
local tween2 = tweenService:Create(blade, tweenInfo, goal2)
return tween1, tween2
end
-- function to play the tweens
local function playTweens()
local tween1, tween2 = createTweens()
tween1:Play()
tween2:Play()
end
-- detect the key
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode == Enum.KeyCode.E then
playTweens()
end
end)