Need help with slide tackle system

  1. I want to achieve a slide tackle to steal ball system

  2. Touched event does not stop firing after usage, even after script ends.

  3. I’ve tried debounces and TouchEnded so far.

LocalScript

local GameLogs = game.ReplicatedStorage.Events.GameLogs
local Kick = true
local uis = game:GetService("UserInputService")
local deb = false
local cd = 6
local CollectionService = game:GetService("CollectionService")
local antiSpamSteal = false
local touched = false

local Tag = "IFrames"

local character = Player.Character or Player.CharacterAdded:Wait()
local Tackle = character:WaitForChild("Humanoid"):LoadAnimation(script.Animation)

uis.InputBegan:Connect(function(input, gameProcessedEvent)
	print("Test1")
	if input.KeyCode == Enum.KeyCode.T and not gameProcessedEvent and deb == false and antiSpamSteal == false  then
		antiSpamSteal = true
		print("Test2")
		deb = true
		Tackle:Play()
		local velocity = Instance.new("BodyVelocity")
		velocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		velocity.Velocity = Player.Character.Torso.CFrame.lookVector * 100
		velocity.Parent = Player.Character.HumanoidRootPart
		game.Debris:AddItem(velocity, 0.1)
		character["Right Leg"].TouchEnded:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
					local plrhit = game.Players:GetPlayerFromCharacter(hit.Parent)	
					if hit.Parent:FindFirstChild("Humanoid") and plrhit and plrhit.TeamColor == Player.TeamColor then
						print('Can\'t tackle teammates')
					end
						if hit.Parent:FindFirstChild("Humanoid") and CollectionService:HasTag(plrhit.Character, Tag) then
							print("Cant steal from IFrames")
						end
				if hit.Parent:FindFirstChild("Humanoid") and not CollectionService:HasTag(plrhit.Character, Tag) then 
						print("Test3 success")
						game.ReplicatedStorage.Events.Trip_Player:FireServer(hit)
						GameLogs:FireServer(hit.Parent.Name)
						Kick = false
					end
			end
			if not hit.Parent:FindFirstChild("Humanoid") then
					print("Nothing Detected!")
				end
			end)
		task.wait(6)
		print("CD TEST")
		deb = false
		antiSpamSteal = false
	end		
end)	

game.ReplicatedStorage.Events.Stolen.OnClientEvent:Connect(function()
	Kick = true
end) 

ServerScript

	local plrhit = game.Players:GetPlayerFromCharacter(hit.Parent)	
	
	local plrToRef = player
	
	if plrhit.Backpack.HasBall.Value == true then
		if script.CurrentPlayer.Value == plrhit.Character then
			plrhit.Character:WaitForChild("Ball_Weld"):Destroy()
			
			plrhit.Backpack.HasBall.Value = false
			
			ball.Script.Hitted.Value = true
			
			script.CurrentPlayer.Value = player.Character
			
			player.Backpack:WaitForChild("HasBall").Value = true
			
			ball.CanCollide = true
			
			local Weld = Instance.new("Motor6D",player.Character)
			Weld.Part0 = player.Character.HumanoidRootPart
			Weld.Part1 = ball
			Weld.Name = "Ball_Weld"
			Weld.C0 = CFrame.new(0.5,-2.5, -1)

			ball.CanCollide = false
		end
	end
end)

example:

Check if this works out for your LocalScript. I changed a few things, like an added end, defined Player, defined Character, and changed the little task wait you have into a regular wait.

local GameLogs = game.ReplicatedStorage.Events.GameLogs
local Kick = true
local uis = game:GetService("UserInputService")
local deb = false
local cd = 6
local CollectionService = game:GetService("CollectionService")
local antiSpamSteal = false
local touched = false

local Tag = "IFrames"

local character = Player.Character or Player.CharacterAdded:Wait()
local Tackle = character:WaitForChild("Humanoid"):LoadAnimation(script.Animation)

uis.InputBegan:Connect(function(input, gameProcessedEvent)
  if input.KeyCode == Enum.KeyCode.T and not gameProcessedEvent and deb == false and antiSpamSteal == false  then
    antiSpamSteal = true
    deb = true
    Tackle:Play()
    local velocity = Instance.new("BodyVelocity")
    velocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    velocity.Velocity = Player.Character.Torso.CFrame.lookVector * 100
    velocity.Parent = Player.Character.HumanoidRootPart
    game.Debris:AddItem(velocity, 0.1)
    character["Right Leg"].TouchEnded:Connect(function(hit)
      if hit.Parent:FindFirstChild("Humanoid") then
        local plrhit = game.Players:GetPlayerFromCharacter(hit.Parent)
        if hit.Parent:FindFirstChild("Humanoid") and plrhit and plrhit.TeamColor == Player.TeamColor then
          print("Can't tackle teammates")
        end
        if hit.Parent:FindFirstChild("Humanoid") and CollectionService:HasTag(plrhit.Character, Tag) then
          print("Cant steal from IFrames")
        end
        if hit.Parent:FindFirstChild("Humanoid") and not CollectionService:HasTag(plrhit.Character, Tag) then 
          game.ReplicatedStorage.Events.Trip_Player:FireServer(hit)
          GameLogs:FireServer(hit.Parent.Name)
          Kick = false
        end
      end
      if not hit.Parent:FindFirstChild("Humanoid") then
        print("Nothing Detected!")
      end
    end)
    wait(6)
    deb = false
    antiSpamSteal = false
  end		
end)	

game.ReplicatedStorage.Events.Stolen.OnClientEvent:Connect(function()
  Kick = true
end)

Try this for your ServerScript.

local plrToRef = player

if plrhit.Backpack:FindFirstChild("HasBall") and plrhit.Backpack.HasBall.Value == true then
  if script:FindFirstChild("CurrentPlayer") and script.CurrentPlayer.Value == plrhit.Character then
    local ballWeld = plrhit.Character:FindFirstChild("Ball_Weld")
    if ballWeld then
      ballWeld:Destroy()
    end

    plrhit.Backpack.HasBall.Value = false

    ball.Script.Hitted.Value = true

    script.CurrentPlayer.Value = player.Character

    player.Backpack:WaitForChild("HasBall").Value = true

    ball.CanCollide = true

    local Weld = Instance.new("Motor6D", player.Character)
    Weld.Part0 = player.Character.HumanoidRootPart
    Weld.Part1 = ball
    Weld.Name = "Ball_Weld"
    Weld.C0 = CFrame.new(0.5, -2.5, -1)

    ball.CanCollide = false
  end
end

To remove an event, you can use this method

local connection
connection = part.Touched:Connect(myFunction)

wait(5)

connection:Disconnect()

If you’re trying to remove some kind of touched event after a certain threshold, use this method rather than debounces, if you won’t be using that same method again for a while. But if the touch event constantly is on and off, you should probably use some kind of variable like a debounce.

1 Like

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