The Pushing In The Ability 1 doubles every times

  1. What do you want to achieve? Keep it simple and clear!

I want to make it so it does not double the pushing every time I use the ability

  1. What is the issue? Include screenshots / videos if possible!

Everytime I use my ability it doubles the push force

Here is the full script

local Configuration = script.Parent:WaitForChild('Configuration')

local Uis = game:GetService('UserInputService')

local Mouse = game:GetService('MouseService')

local Character = script.Parent
local Root = Character:WaitForChild('HumanoidRootPart')

local durationM1 = 1
local Ability1 = 15
local canM1 = true
local CanAbility1 = true
local hitboxMod = require(game.ReplicatedStorage.HitBox)


local Ability2DMG = .5
local Ability1DMG = .5
local M1Dmg = 15

local AllLocked = false

local M1Anim = Character.Humanoid:LoadAnimation(Configuration.Animations.M1)
local XslashAnim = Character.Humanoid:LoadAnimation(Configuration.Animations.XSLASH)

function Ability1()  -- ABILITY 1
	
	if CanAbility1 and AllLocked == false then

		if Configuration.Stats.Linked_Sword.Value == true then	
			CanAbility1 = false
			XslashAnim:Play(0)
			local hitTble = {}
			local hitTble2 = {}
			local hitTble3 = {}
			AllLocked = true

			XslashAnim:GetMarkerReachedSignal("HITBOX"):Connect(function()
				local atch = Instance.new("Attachment")
				atch.Parent = Character.HumanoidRootPart
				local hitbox = hitboxMod.create(atch.WorldCFrame*CFrame.new(0,0,-3), Vector3.new(6, 5, 4), 0.125)
				hitbox.Touched:Connect(function(hit)
					local victim = hit.Parent

					if victim:FindFirstChildWhichIsA("Humanoid") and not table.find(hitTble, victim) and victim ~= Character then
						table.insert(hitTble, victim)
						print(hitTble)
						hitbox.BrickColor = BrickColor.new("Lime green")
						--	print(victim)

						game.ReplicatedStorage.Events.Damage:FireServer(victim,20)


					end
				end)
				task.wait()
			end)
			XslashAnim:GetMarkerReachedSignal("HITBOX2"):Connect(function()
				local atch = Instance.new("Attachment")
				atch.Parent = Character.HumanoidRootPart
				local hitbox = hitboxMod.create(atch.WorldCFrame*CFrame.new(0,0,-3), Vector3.new(6, 5, 4), 0.125)
				hitbox.Touched:Connect(function(hit)
					local victim = hit.Parent

					if victim:FindFirstChildWhichIsA("Humanoid") and not table.find(hitTble2, victim) and victim ~= Character then
						table.insert(hitTble2, victim)
						print(hitTble2)
						hitbox.BrickColor = BrickColor.new("Lime green")
						--	print(victim)

						game.ReplicatedStorage.Events.Damage:FireServer(victim,20)


					end
				end)
				task.wait()
			end)
			XslashAnim:GetMarkerReachedSignal("BIGHITBOX"):Connect(function()
				local atch = Instance.new("Attachment")
				atch.Parent = Character.HumanoidRootPart
				local hitbox = hitboxMod.create(atch.WorldCFrame*CFrame.new(0,0,-3), Vector3.new(7.5, 5, 6), 0.125)
				hitbox.Touched:Connect(function(hit)
					local victim = hit.Parent

					if victim:FindFirstChildWhichIsA("Humanoid") and not table.find(hitTble3, victim) and victim ~= Character then
						table.insert(hitTble3, victim)
						print(hitTble3)
						hitbox.BrickColor = BrickColor.new("Lime green")
						--	print(victim)

						game.ReplicatedStorage.Events.Damage:FireServer(victim,35)


					end
				end)
				task.wait()
			end)

			XslashAnim:GetMarkerReachedSignal("PUSH"):Connect(function()
				
				local mass = Root.AssemblyMass

				local force = Vector3.new(0,0,-3000*2)*mass
				local vf2 = Instance.new("VectorForce")
				vf2.ApplyAtCenterOfMass = true
				vf2.Attachment0 = Root.RootAttachment
				vf2.Force = force
				vf2.Parent = Root
				task.wait(.01)
				vf2:Destroy()
				
			end)
			XslashAnim:GetMarkerReachedSignal("BIGPUSH"):Connect(function()
				local mass = Root.AssemblyMass

				local force = Vector3.new(0,0,-4000*2)*mass
				--local force = Vector3.new(0,0,-2*2)*mass
				local vf2 = Instance.new("VectorForce")
				vf2.ApplyAtCenterOfMass = true
				vf2.Attachment0 = Root.RootAttachment
				vf2.Force = force
				vf2.Parent = Root
				task.wait(.01)
				vf2:Destroy()
			end)
		task.wait(XslashAnim.Length+0.05)

		AllLocked = false
		task.wait(1)
		CanAbility1 = true
	
		end
	end
end

function Slash() -- M1 ABILITY
	
	--[[local Speed = 40
	local Force = 80000

	local TotalForce = Force

	local KnockBack = Instance.new("BodyVelocity")
	KnockBack.Parent = part.Parent:FindFirstChild("HumanoidRootPart")--part is the target of the knockback/ the opponent

	KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
	KnockBack.Velocity = Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * Speed -- based on the direction YOUR character is facing.]]
	
	if canM1 and AllLocked == false then
			
		if Configuration.Stats.Linked_Sword.Value == true then	
			
			print("Swing")
			
			canM1 = false
			M1Anim:Play(0)
			local hitTble = {}
			AllLocked = true


			M1Anim:GetMarkerReachedSignal("HITBOX"):Connect(function()

				local atch = Instance.new("Attachment")
				atch.Parent = Character.HumanoidRootPart
				local hitbox = hitboxMod.create(atch.WorldCFrame*CFrame.new(0,0,-3), Vector3.new(6, 5, 4), 0.125)
					hitbox.Touched:Connect(function(hit)
						local victim = hit.Parent

						if victim:FindFirstChildWhichIsA("Humanoid") and not table.find(hitTble, victim) and victim ~= Character then
							table.insert(hitTble, victim)
							print(hitTble)
							hitbox.BrickColor = BrickColor.new("Lime green")
						--	print(victim)
							
							game.ReplicatedStorage.Events.Damage:FireServer(victim,M1Dmg)
							

						end
					end)
					task.wait()
			
			end)
		
		

		task.wait(M1Anim.Length+0.05)
		
		AllLocked = false
		
		task.wait(durationM1-M1Anim.Length-0.05)
		
		canM1 = true
		end
	end
end

Uis.InputBegan:Connect(function(input)
	
	if (Uis:GetFocusedTextBox()) then return end
	
	if input.KeyCode == Enum.KeyCode.E then
		
		Ability1()
		
	elseif input.KeyCode == Enum.KeyCode.Q then
		
		print("Ability 2")

	elseif input.KeyCode == Enum.KeyCode.R then
	
	
		print("Ability 3")


	end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		
		Slash()
		
	end
	
end)


Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

That’s too long of code for me to read through, but I will give you 2 ideas of what the problem may be. The first one is just that horizontal force like this can conflict with friction or something which makes the size unpredictable. I’ll often write something like this then have to tune it forever to get it to do what I want it to consistently.

Second is a common bug, make sure your ability is not activating N times and adding N forces to you. A lot of times people often accidentally bind to an event multiple times so every event fires it for every connection that ever took place. So like if you never :Disconnect() your GetMarkerReachedSignal("PUSH"), then you may be running an extra copy of that function every time you attack which will mean extra forces added.

A quick test to see if it’s this last one is to replace your :Connect() with :Once() which will only run it one time before automatically disconnecting. Note though that this is not necessarily the best solution as you may still end up in situations where they stack until it actually triggers, but whether that will happen or not depends on your code and the strategy you use depends on your code.

Thank you so much I replaced The :Connect() with :Once() and now it works!

1 Like

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