I need a bit of help with this script

So I started developing a MPS game and for a slide tackle animation, I’m trying to make the slide tackle animation play and then stop playing.
The animation continues playing when its not suppost to and it changes to a walking animation.
I turned off looping which didn’t do anything.

Heres the script for it -

local TM = require(script.Parent.Parent:WaitForChild("ToolManagment"))
local Tween = require(script.Parent.Parent:WaitForChild("Module_Management"):WaitForChild("Tweening"))
local GetUp2 = require(script.Parent.Parent:WaitForChild("GetUp"))
local RightAnim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.R)
local LeftAnim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.L)
Kick = false
Equipped = false

Tool = script.Parent
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()

Speed = 38
Range = 300

script.Parent.Equipped:connect(function(m)
	Equipped = true
end)

script.Parent.Unequipped:connect(function(m)
	Equipped = false
end)


Mouse.Button1Down:connect(function()
	if not workspace.Configuration.SlideTackle.Value then return end
	if not CloseEnoughToABall() then return end
	if Equipped == false then return end
	if TM.GetUsing() then return end
	workspace.Camera.CameraSubject = Player.Character.Humanoid
	TM.SetUsing(true)

	Player.Character.Torso.RotVelocity = Vector3.new()
	Player.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

	local SF = Instance.new("BodyVelocity")
	SF.Parent = Player.Character["Torso"].Parent.HumanoidRootPart
	SF.MaxForce = Vector3.new(math.huge,0,math.huge)
	SF.Velocity = Player.Character["Torso"].Parent.HumanoidRootPart.CFrame.lookVector * 25
	game.Debris:AddItem(SF, 1.3)

	local Direction = Enum.EasingDirection.Out
	local Style = Enum.EasingStyle.Back
	local Duration = 0.4

	Player.Character.Humanoid.WalkSpeed = 0
	Player.Character.Humanoid.JumpPower = 0
	Player.Character.Humanoid.AutoRotate = true

	Player.Character.HumanoidRootPart.CollisionGroupId = 0
	Player.Character["Right Leg"].CollisionGroupId = 0
	Player.Character["Left Leg"].CollisionGroupId = 0
	Player.Character["Right Arm"].CollisionGroupId = 0
	Player.Character["Left Arm"].CollisionGroupId = 0
	Player.Character["Torso"].CollisionGroupId = 0
	Player.Character["Head"].CollisionGroupId = 0

	if TM.check() == "R" then
		RightAnim:Play()
	else
		LeftAnim:Play()
	end
	Kick = true
	wait(1.3)
	TM.ResetWelds()
	Player.Character.Humanoid.AutoRotate = false
	Kick = false
	SF.Velocity = Player.Character["Torso"].Parent.HumanoidRootPart.CFrame.lookVector * 0
	wait(0.6)
	Player.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	Player.Character.Humanoid.PlatformStand = false
	Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	Player.Character.HumanoidRootPart.CollisionGroupId = 0
	Player.Character["Right Leg"].CollisionGroupId = 0
	Player.Character["Left Leg"].CollisionGroupId = 0
	Player.Character["Right Arm"].CollisionGroupId = 0
	Player.Character["Left Arm"].CollisionGroupId = 0
	Player.Character["Torso"].CollisionGroupId = 0
	Player.Character["Head"].CollisionGroupId = 0
	Player.Character.Humanoid.WalkSpeed = 20
	Player.Character.Humanoid.JumpPower = 50
	Player.Character.Humanoid.AutoRotate = true
	wait(1.2)
	TM.SetUsing(false)
end)

Player.Character["Right Leg"].Touched:connect(function(hit)
	if Kick == false then return end
	if hit.Parent:FindFirstChild("Humanoid") then
		game.ReplicatedStorage.Trip_Player:FireServer(hit.Parent)
		Kick = false
	end
	if hit.Name ~= "TPS" then return end
	local force = Player.Character["Right Leg"].CFrame.lookVector * 70
	local angle = Vector3.new(9000,1000,9000)
	Kick = false
	TM.ApplyForce(hit, angle, force, "Right Leg")
end)

Player.Character["Left Leg"].Touched:connect(function(hit)
	if Kick == false then return end
	if hit.Parent:FindFirstChild("Humanoid") then
		game.ReplicatedStorage.Trip_Player:FireServer(hit.Parent)
		Kick = false
	end
	if hit.Name ~= "TPS" then return end
	local force = Player.Character["Left Leg"].CFrame.lookVector * 70
	local angle = Vector3.new(9000,1000,9000)
	Kick = false
	TM.ApplyForce(hit, angle, force, "Left Leg")
end)

function CloseEnoughToABall()
	--[[
		unfortunately you dont use
		collectionservice to track the balls or anything in general, so i have to use
		more inefficient method.
	--]]
	local Character = Player.Character
	if not Character then return end
	local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
	if not HumanoidRootPart then return end
	local CharacterPosition = HumanoidRootPart.Position

	-- DFC stands for distance from character
	local ClosestBall
	local ClosestBallDFC

	local Children = workspace:GetChildren()
	for _, Child in pairs(Children) do
		if Child.Name == "TPS" then
			local DescendantPosition = Child.Position
			if ClosestBall and ClosestBallDFC then
				local DistanceFromCharacter = (CharacterPosition - DescendantPosition).Magnitude
				if DistanceFromCharacter < ClosestBallDFC then
					ClosestBall = Child
					ClosestBallDFC = DistanceFromCharacter
				end
			else
				local DistanceFromCharacter = (CharacterPosition - DescendantPosition).Magnitude
				ClosestBall = Child
				ClosestBallDFC = DistanceFromCharacter
			end
		end
	end

	if ClosestBallDFC then
		if ClosestBallDFC < Range then
			return true
		else
			return false
		end
	else
		return false
	end
end

function ChangeOwner(ball)
	game.ReplicatedStorage.ChangeOwner:FireServer(ball)
end

It also might just be a issue with the animation itself, im not sure.

if TM.check() == "R" then
        RightAnim:Play()
    else
        LeftAnim:Play()
    end

    wait(1.3)

    RightAnim:Stop()
    LeftAnim:Stop()
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.