Gore System Error

Hello, I was doing a Gore System and I have an error that is taking me too long

The error it has is that when you attack the FIRST time it works normally, but when you make the SECOND attack it doesn’t work anymore

I made two changes in some scripts that fixed the previous error, but those changes made a new error

The changes I made were in these two scripts

The first change i made was to Melee_Client

local module = {}

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Utilities = require(ReplicatedStorage.Assets.Modules.Utilities)
local RaycastHitboxV4 = require(ReplicatedStorage.Assets.Modules.RaycastHitboxV4)

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local UserInputService = game:GetService("UserInputService")
local ClickInputs = {Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch}

local function WaitUntil(Value)
	repeat task.wait() until Value
end
local function WaitUntilLoaded(Object, String)
	WaitUntil(Object:FindFirstChild(String))
	return Object[String]
end

function module.Start(Tool)
	if not Tool:IsA("Tool") then
		error("[!] ".. Tool.Name .. " is not a tool.")
		return
	end
	local Handle = WaitUntilLoaded(Tool, "Handle")
	local Settings = WaitUntilLoaded(Tool, "Settings")
	Settings = require(Settings)

	local ModelsHit = {}
	local Params = RaycastParams.new()
	Params.FilterDescendantsInstances = {Tool}
	Params.FilterType = Enum.RaycastFilterType.Exclude -- this is the same as blacklist.

	local Connections = {}
	local Dismemberment = {}
	local Character = nil
	local Humanoid = nil
	local IsEquipped = false
	local IsActive = false
	local IsInspecting = false
	local IsSwinging = false
	local IsFinishing = false
	local HitFloor = false
	local CurrentAnimationNumber = 0

	local EquipAnimation
	local IdleAnimation
	local SwingAnimation
	local InspectAnimation
	local FinishAnimation

	local function ChangeTrails(Bool, Color)
		if not Settings.Settings.TrailsEnabled[1] then
			return
		end
		for i,v in pairs(Handle:GetChildren()) do
			if v:IsA("Trail") then
				if Bool ~= nil then
					v.Enabled = Bool
				end
				if Color then
					v.Color = ColorSequence.new(Color)
				else
					v.Color = ColorSequence.new(Settings.Settings.TrailsEnabled.Color)
				end
			end
		end
	end

	local Hitbox = RaycastHitboxV4.new(Handle)
	Hitbox.RaycastParams = Params
	Hitbox.Visualizer = false
	Hitbox.DetectionMode = 2
	Hitbox.OnHit:Connect(function(Object, _, RaycastResult)
		local Model = Object:FindFirstAncestorOfClass("Model")
		local Humanoid = Model and Model:FindFirstChildOfClass("Humanoid")
		if Humanoid and Object.Parent:FindFirstChildOfClass("Humanoid") then
			if (Humanoid and Object.Parent:FindFirstChildOfClass("Humanoid") and not ModelsHit[Humanoid] and Object.Name ~= "HumanoidRootPart" and ((IsFinishing and Humanoid.Health <= Settings.Settings.FinishingHealth) or (not IsFinishing))) or (not Humanoid and not HitFloor) then
				if (Humanoid and Object.Parent:FindFirstChildOfClass("Humanoid")) then
					ModelsHit[Humanoid] = true
					ChangeTrails(nil, Settings.Settings.TrailsEnabled.HitColor)
				elseif (not Humanoid) then
					HitFloor = true
				end
				ReplicatedStorage.Assets.Events.Melee_Main:FireServer({
					Action = "Hit",
					Tool = Tool,
					Hit = Object,
					Humanoid = Humanoid or nil,
					RayPosition = RaycastResult.Position,
					RayNormal = RaycastResult.Normal,
					Dismemberment = Dismemberment,
					Finishing = IsFinishing,
				})
			end
		end
	end)

	local function UpdateSwingAnimation()
		if CurrentAnimationNumber == 0 then
			CurrentAnimationNumber = 1
		end
		SwingAnimation = Utilities.LoadAnimation(Settings.Animations.Swing[CurrentAnimationNumber].AnimationId, Humanoid)
		SwingAnimation:GetMarkerReachedSignal("HitStart"):Connect(function()
			HitFloor = false
			table.clear(ModelsHit)
			Hitbox:HitStart()
			ChangeTrails(true)
			ReplicatedStorage.Assets.Events.Melee_Main:FireServer({
				Action = "Swing",
				Tool = Tool,
			})
		end)
		SwingAnimation:GetMarkerReachedSignal("HitStop"):Connect(function()
			Hitbox:HitStop()
			ChangeTrails(false)
		end)
		Dismemberment = Settings.Animations.Swing[CurrentAnimationNumber].Dismemberment
		CurrentAnimationNumber = CurrentAnimationNumber + 1
		if CurrentAnimationNumber > #Settings.Animations.Swing then
			CurrentAnimationNumber = 1
		end
	end
	local function FindTarget()
		local Target = nil
		if not Settings.Settings.FinishingUsesRaycast then
			for i,v in pairs(workspace:GetDescendants()) do
				if v:IsA("Model") and v:FindFirstChildOfClass("Humanoid") and v ~= Character then
					Target = v
					break
				end
			end
		else
			local RayHit, RayPosition, RayNormal = workspace:FindPartOnRayWithIgnoreList(Ray.new(Character.HumanoidRootPart.Position, Character.HumanoidRootPart.CFrame.LookVector * 5 - Vector3.new(0, 1.5, 0)), {Character, workspace.Debris})
			local Model = RayHit and RayHit:FindFirstAncestorOfClass("Model")
			local ModelHumanoid = Model and Model:FindFirstChildOfClass("Humanoid")
			if ModelHumanoid then
				Target = Model
			end
		end
		return Target
	end

	Connections.Equipped = Tool.Equipped:Connect(function()
		IsEquipped = true
		Character = Tool.Parent
		Humanoid = Character:WaitForChild("Humanoid")
		Params.FilterDescendantsInstances = {Tool, Character}

		if not EquipAnimation and not IdleAnimation and not InspectAnimation and not FinishAnimation and not SwingAnimation then
			if Settings.Settings.EquipAnimation then
				EquipAnimation = Utilities.LoadAnimation(Settings.Animations.Equip.AnimationId, Humanoid)
				EquipAnimation.Stopped:Connect(function()
					if IsEquipped and IdleAnimation then
						IsActive = true
						Utilities.PlayAnimation(IdleAnimation, Settings.Animations.Idle)
					end
				end)
			end
			if Settings.Settings.IdleAnimation then
				IdleAnimation = Utilities.LoadAnimation(Settings.Animations.Idle.AnimationId, Humanoid)
			end
			if Settings.Settings.InspectingEnabled then
				InspectAnimation = Utilities.LoadAnimation(Settings.Animations.Inspect.AnimationId, Humanoid)
				InspectAnimation.Stopped:Connect(function()
					IsInspecting = false
				end)
			end
			if Settings.Settings.FinishingEnabled then
				FinishAnimation = Utilities.LoadAnimation(Settings.Animations.Finish.AnimationId, Humanoid)
				FinishAnimation.Stopped:Connect(function()
					Humanoid.WalkSpeed = 16
					IsFinishing = false
				end)
				FinishAnimation:GetMarkerReachedSignal("HitStart"):Connect(function()
					HitFloor = false
					table.clear(ModelsHit)
					Hitbox:HitStart()
					ChangeTrails(true)
					ReplicatedStorage.Assets.Events.Melee_Main:FireServer({
						Action = "Swing",
						Tool = Tool,
					})
				end)
				FinishAnimation:GetMarkerReachedSignal("HitStop"):Connect(function()
					Hitbox:HitStop()
					ChangeTrails(false)
				end)
			end
		end
		if EquipAnimation then
			Utilities.PlayAnimation(EquipAnimation, Settings.Animations.Equip)
		else
			IsActive = true
			if IdleAnimation then
				Utilities.PlayAnimation(IdleAnimation, Settings.Animations.Idle)
			end
		end
	end)
	Connections.Unequipped = Tool.Unequipped:Connect(function()
		IsEquipped = false
		IsActive = false
		if EquipAnimation then
			EquipAnimation:Stop()
		end
		if IdleAnimation then
			IdleAnimation:Stop()
		end
		if Settings.Settings.StopSwingAnimationWhenUnequipped then
			if SwingAnimation then
				SwingAnimation:Stop()
			end
			ChangeTrails(false)
			Hitbox:HitStop()
			HitFloor = false
		end
		if Settings.Settings.StopInspectAnimationWhenUnequipped then
			if InspectAnimation then
				InspectAnimation:Stop()
			end
		end
		if FinishAnimation then
			FinishAnimation:Stop()
		end
		if Humanoid then
			Humanoid.WalkSpeed = 16
		end
	end)
	Connections.Destroying = Tool.Destroying:Connect(function()
		for i,v in pairs(Connections) do
			v:Disconnect()
			Connections[i] = nil
		end
	end)
	--[[if (not Settings.Settings.InspectingEnabled and not Settings.Settings.FinishingEnabled) then
		return
	end]]
	Connections.Input = UserInputService.InputBegan:Connect(function(Input, GameProcessed)
		if GameProcessed then
			return
		end
		if Settings.Settings.InspectingEnabled then
			if Input.KeyCode == Settings.Settings.InspectingKeybind then
				if not IsInspecting and IsActive and not IsFinishing and not IsSwinging then
					IsInspecting = true
					Utilities.PlayAnimation(InspectAnimation, Settings.Animations.Inspect)
				end
			end
		end
		if Settings.Settings.FinishingEnabled then
			if Input.KeyCode == Settings.Settings.FinishingKeybind then
				if not IsInspecting and IsActive and not IsFinishing and not IsSwinging then
					local Target = FindTarget()
					local TargetHumanoid = Target and Target:FindFirstChildOfClass("Humanoid")
					if TargetHumanoid and TargetHumanoid.Health <= Settings.Settings.FinishingHealth and (Target.HumanoidRootPart.Position - Character.HumanoidRootPart.Position).Magnitude <= Settings.Settings.FinishingRange then
						IsFinishing = true
						Utilities.PlayAnimation(FinishAnimation, Settings.Animations.Finish)
						Dismemberment = Settings.Animations.Finish.Dismemberment
						Humanoid.WalkSpeed = Settings.FinishingWalkSpeed
						local Connection
						Connection = Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
							Connection:Disconnect()
							if IsFinishing then
								IsFinishing = false
								FinishAnimation:Stop()
							end
						end)
						table.insert(Connections, Connection)
					end
				end
			end
		end
		if table.find(ClickInputs, Input.UserInputType) and IsActive and not IsInspecting and not IsFinishing then
			if not IsSwinging then
				IsSwinging = true
				UpdateSwingAnimation()
				Utilities.PlayAnimation(SwingAnimation, Settings.Animations.Swing)
			end
		end
	end)
end

return module

The other change was to Utilities, the error I had was that with that script the animations were executed

At the time of making those two changes to those two scripts, one was the one that broke the attack

Here is the Utilities script

local module = {}
local anims = {}

function module.Weld(Part0, Part1, Parent, Name, Bool)
	local Weld
	if Bool then
		Weld = Instance.new("WeldConstraint")
	else
		Weld = Instance.new("Weld")
	end
	Weld.Part0 = Part0
	Weld.Part1 = Part1
	Weld.Name = Name or Weld.Name
	Weld.Parent = Parent or Part0
end
function module.LoadAnimation(AnimationId: string, Object: Humanoid)
	local AnimationTrack = nil
	local Animation = Instance.new("Animation")
	Animation.AnimationId = AnimationId
	Animation = Object.Animator:LoadAnimation(Animation)
	-- instead of using Object:LoadAnimation (Deprecated), you should use Object.Animator:LoadAnimation()
	return Animation
end
function module.PlayAnimation(Animation: AnimationTrack, Table: table)
	Animation:Play()
	Animation.Priority = Table.AnimationPriority
	Animation:AdjustSpeed(Table.AnimationSpeed)
	Animation.Looped = Table.Looped
	if not anims[Animation] then
		anims[Animation] = true
		for i,v in pairs(Table.AnimationEvents) do
			Animation:GetPropertyChangedSignal(v.AnimationEventName):Connect(function()
				v.Function()
			end)
		end
	end
end
function module.Random(A, B)
	return Random.new():NextNumber(A, B)
end
function module.ReturnRandom(Value: table)
	return Value[math.random(#Value)]
end
function module.ReturnChildren(Folder)
	return Folder:GetChildren()
end
function module.ReturnFolderChild(Folder)
	return module.ReturnRandom(module.ReturnChildren(Folder))
end
function module.PlaySound(SoundBase: Sound, Parent: BasePart?)
	local Sound = SoundBase:Clone()
	Sound.Parent = Parent
	Sound:Play()
	Sound.Ended:Connect(function()
		Sound:Destroy()
	end)
end

return module

The person who manages to solve this problem, I will be waiting for their posts in the devforum to provide help in their scripts. Obviously also to those who tried to help

Thank you

1 Like

Im not very advanced at scripting, but may I know the error from the output?

is the first module a one-for-all modulescript for all of your tools?

theres is not a error in the output

yes, with that script the tools works