How to tween a slide on a gun tool?

ive been trying to tween the slide of a gun when it shoots but I cant seem to figure it out because tween dont work with tools. I tried using motor6d motor6d is only capable of rotating not the back and forth motion of the slide. And btw I cannot use an animation to tween it, it needs to be an actual script.

So, have the slide be welded to the gun, weld it to the gun. You’ll need a TweenService in your script and you’ll just have to do something like this whenever it get’s shot:

TweenService = game:GetService("TweenService")

TweenerInfo = TweenInfo.new(0.35, Enum.EasingStyle.Sextic, Enum.EasingDirection.Out, 0, true)

local shotAnimation = TweenService:Create(--[[Replace this part with wherever the weld is at]], 
TweenerInfo, 
{C1 = CFrame.new(Vector3.new(0, 0, C1.CFrame.LookVector.Z - 0.4), C1.CFrame.Orientation)})
Tool.Activated:Connect(function()

shotAnimation:Play()
end)

You need to fix thiss code to best fit for your situation, this code is very scuffed since I don’t have details of the slider part. If you need more help, let me know.

but tweenservice doesnt work in parts for some reason

How does your setup look like? It should work in parts so you must have set it wrongly.

i tried this but i get the error CFrame is not a valid member of CFrame? btw sorry for late reply

How’s your code looking right now?

local TweenService = game:GetService("TweenService")

			local TweenerInfo = TweenInfo.new(0.35, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, true)

			local shotAnimation = TweenService:Create(script.Parent.Gun.Barrel.qCFrameWeldThingy, 
				TweenerInfo, 
				{C1 = CFrame.new(Vector3.new(0, 0, script.Parent.Gun.Barrel.qCFrameWeldThingy.C1.CFrame.LookVector.Z - 0.4), script.Parent.Gun.Barrel.qCFrameWeldThingy.C1.CFrame.Orientation)})

				shotAnimation:Play()

My bad. Remove the CFrame between the C1 and LookVector.

still the same error… Barrel.qCFrameWeldThingy.C1.LookVector.Z wait im going to try it with the cframe removed on the other line too, alright when i do that it says orientation is not a valid member of cframe

Just try searching other posts.
I typed in “gun slide animation” and came up with a few posts about it, one that mentions tweening in the description.

right but like I stated in my post I cant use animations, I need to use tweenservice.

any idea for a fix since that didnt work?

I mentioned tweenservice in that post as well…

Could you give me a place file so I can look at it and do my trial and errors?

Also, what type of weld is it? That’s a contribution to the problem. If it was a WeldConstraint, it wouldn’t have either C1 or C0.

instead of using C1 you can possibly using CFrame instead

local shotAnimation = TweenService:Create(script.Parent.Gun.Barrel, 
				TweenerInfo, 
				{C1 = CFrame.new(Vector3.new(0, 0, script.Parent.Gun.Barrel.CFrame.LookVector.Z - 0.4), script.Parent.Gun.Barrel.CFrame.Orientation)})

Zylo all you have to do is create a motor6d to the weapons handle and animate it accordingly with the motor6d.

the motor6d allows you to freely move the slide part anyway u want forward backward etc .

the use of animations to move the slide is very simple yet not so hard to accomplish.

i have done it several times etc in my gun system.

DO NOT WELD ANIMATED PARTS u motor6d them.
and tweening parts of weapons is not really ideal

if this was ur answer please set this as the solution.

IF YOU WANT TO LEARN ABT THIS PLS GO HERE!

A POST BY HEADSTACKK ON HOW TO ANIMATE PARTS

its a normal weld, no weldconstraint.

but I need my thing to be in a script and with no animations.

why? just add an animation and load the animation each time ur shooting event is fired.