I want to access the tween in the above if statement, how would I do that?
local function Slide(name, state, type)
if state == Enum.UserInputState.Begin and canslide then
canslide = false
local animation = Instance.new("Animation")
animation.AnimationId = 'rbxassetid://18306255547'
local SlideTrack = Humanoid:FindFirstChildOfClass("Animator"):LoadAnimation(animation)
SlideTrack:Play()
local SlideVal = Instance.new("NumberValue")
SlideVal.Value = WalkSpeedV.Value * 2
Humanoid.WalkSpeed = 0
local speed = SlideVal
local speedup = RunService.RenderStepped:Connect(function()
SlideTrack:AdjustSpeed(speed.Value)
end)
local SpeedCap = RunService.Stepped:Connect(function()
if SlideVal.Value > 25 then
SlideVal.Value = 25
end
end)
local SlideTween = TweenService:Create(speed, TweenInfo.new(speed.Value/2), {Value = 0})
local BV = Instance.new("BodyVelocity")
BV.Parent = Character.PrimaryPart
BV.MaxForce = Vector3.new(math.huge, 0, math.huge)
SlideTween:Play()
local VelocityStep = RunService.Stepped:Connect(function()
BV.Velocity = HumanoidRP.CFrame.LookVector * speed.Value
end)
SlideTween.Completed:Connect(function()
issliding = false
Humanoid.WalkSpeed = 15
SlideTrack:Stop()
BV:Destroy()
SlideTween:Destroy()
SlideVal:Destroy()
animation:Destroy()
speedup:Disconnect()
VelocityStep:Disconnect()
task.wait(1)
canslide = true
end)
end
if state == Enum.UserInputState.End then
print("ended")
-- End Tween, Stop Animation, Destroy Tween, Destroy BV, Destroy Animation
end
end