Error when loading module

Hello, I’ve been working on a combat system and I’m having an error that’s too hard to fix.

The error is to keep a record of the first spawned character when a character respawns.

This isn’t the first time I’ve seen this error, a fluke fixed it some time ago, but I’m not sure what the exact reason it’s appearing is.

The first change I made was to the script to load the module.

require(script:WaitForChild("Client")):new()

I don’t know the exact reason as this script just loads the module.

The second script is Module_Client which loads all modules.

local module = {}

function module:new()
local Utils = script:WaitForChild("Utils")
local FunctionModule = require(Utils:WaitForChild("FunctionModule"))
local Animate = require(script:WaitForChild("Animate"))
local Dash = require(script:WaitForChild("Dash"))
local MeleeClient = require(script:WaitForChild("MeleeClient"))
local Sprint = require(script:WaitForChild("Sprint"))
local Jump = require(script:WaitForChild("Jump"))
local OnClientEvents = require(script:WaitForChild("OnClientEvents"))
local Falling = require(script:WaitForChild("Falling"))

FunctionModule:Inti()
end

return module

I’ve searched a lot on how to fix this problem, but I can’t find the exact reason. This problem is an error that appears on the server as well as on the client, and it is an error that appears when loading the module.

For reference, this script is used by StarterCharacterScripts.

2 Likes

Did you possibly misspell :Init()?

Also, you should probably change :new() into .new as you don’t need access to self.

If there’s an error log, please send that if the above doesn’t fix your issue!

Now that I checked, Module_Client seems to be working fine, but there seems to be a problem with the modules loaded into the Module_Client module.

local UserInputService = game:GetService("UserInputService")
local PlayersService = game:GetService("Players")
local RunService = game:GetService("RunService")

local Communication = game.ReplicatedStorage:WaitForChild("Communication")
local Framework = game.ReplicatedStorage:WaitForChild("Framework")
local Assets = game.ReplicatedStorage:WaitForChild("Assets")
local Functions = Communication:WaitForChild("Functions")
local Events = Communication:WaitForChild("Events")

local MeleeModule = {}

local Player = PlayersService.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local PlayerConfigs = Character:WaitForChild("PlayerConfigs")
local Mouse = Player:GetMouse()

local Item = nil
local Attribute = nil
local ItemModel = nil
local HitboxPart = nil
local HandMotor = nil
local Handle = nil
local Datas = nil
local Animations = nil

local EquipType = 0
local Equipped = false
local Slashied = false
local Slashing = false
local Parried = false
local Parrying = false
local ParryDebounce = false
local Combo = 1

local ServerConfigs = require(game.ReplicatedStorage:WaitForChild("ServerConfigs"))
local CheckClass = require(Framework:WaitForChild("CheckClass"))
local FunctionModule = require(script.Parent.Utils:WaitForChild("FunctionModule"))

local AnimationTracks = {
	Equip = nil,
	Idle = nil,
	Holster = nil,
	Swings = {
		[1] = nil,
		[2] = nil,
		Combo = nil,
	},
	Parry = Humanoid:LoadAnimation(Assets.Animations.Parry),
	Dazed = Humanoid:LoadAnimation(Assets.Animations.Dash),
}

function MeleeModule:IsItem(child)
	if not child:FindFirstChild("Attribute") or not child:FindFirstChild("Swing") then return false end
	
	return true
end

function MeleeModule:CanEquip(tool)
	if not Character or not tool or not Character:FindFirstChild("Humanoid") then return false end
	
	return true
end

function MeleeModule:CanSwing()
	if Equipped then
		if not Slashing and not Slashied then
			return true
		else
			return false
		end
	end
end

function MeleeModule:CanParrying()
	if Equipped then
		if PlayerConfigs.PlayerControl.Value then
			if not PlayerConfigs.Dazed.Value and not PlayerConfigs.Rolling.Value then
				if ParryDebounce and not Parried then
					return true
				else
					return false
				end
			else
				return false
			end
		else
			return false
		end
	else
		return false
	end
end

function MeleeModule:swingStart()
	Slashied = true
	Slashing = true
end

function MeleeModule:swingEnd()
	Slashing = false
end

function MeleeModule:swingDisable()
	Slashied = false
end

function MeleeModule:setCombo()
	if Combo == 1 then
		Combo = 2
	elseif Combo == 2 then
		Combo = 1
	end
end

function MeleeModule:parryingStart()
	Parried = true
	Parrying = true
end

function MeleeModule:parryingEnd()
	Parrying = false
end

function MeleeModule:parryingDisable()
	Parried = false
end

function MeleeModule:IsToolandIsModelandData(t,m,d)
	if not t or not m or not d then return false end
	
	return true
end

function MeleeModule:newModel()
	if EquipType == 0 then
		return PlayerConfigs.ItemModel.Value
	else
		return ItemModel
	end
end

function MeleeModule:EquipEvent(tool)
	if MeleeModule:CanEquip(tool) then
		local ItemCheck = tool
		local ModelCheck = MeleeModule:newModel()
		local DataCheck = Assets.ItemDatas:FindFirstChild(tool.Name)

		if MeleeModule:IsToolandIsModelandData(ItemCheck,ModelCheck,DataCheck) then
			Equipped = true
			ParryDebounce = true
			Item = ItemCheck
			ItemModel = ModelCheck
			Datas = DataCheck

			Attribute = require(Item.Attribute)
			HitboxPart = ItemModel.Hitboxes["1"]
			HandMotor = ItemModel.Motor6Ds.Handle
			Handle = ItemModel.Contents.Handle
			Animations = Datas.Animations
			
			AnimationTracks.Equip = Humanoid:LoadAnimation(Animations.Equip)
			AnimationTracks.Idle = Humanoid:LoadAnimation(Animations.Idle)
			AnimationTracks.Holster = Humanoid:LoadAnimation(Animations.Holster)
			AnimationTracks.Swings[1] = Humanoid:LoadAnimation(Animations.Swings["1"])
			AnimationTracks.Swings[2] = Humanoid:LoadAnimation(Animations.Swings["2"])
			
			HandMotor.Part0 = Attribute.Part0(Character)
			HandMotor.Part1 = Attribute.Part1(ItemModel.Contents)
			HandMotor.C0 = Datas.Grip6D.C0
			ItemModel.Parent = Character
			
			AnimationTracks.Holster:Stop()
			AnimationTracks.Equip:Play()
			AnimationTracks.Idle:Play()
			
			Item.Activated:Connect(function()
				MeleeModule:SwingEvent()
			end)
			
			UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
				if gameProcessedEvent then return end
				
				if input.KeyCode == Enum.KeyCode.F then
					MeleeModule:ParryEvent(true)
				end
			end)
			
			Events.Parrying.End.OnClientEvent:Connect(function()
				MeleeModule:ParryEvent(false)
			end)
			
			Events.Dazed.OnClientEvent:Connect(function()
				MeleeModule:DazedEvent()
			end)

			EquipType = 1
		else
			wait()
			Humanoid:UnequipTools()
		end
	end
end

function MeleeModule:UnequipEvent(child)
	if child == Item then
		Equipped = false
		ParryDebounce = false
		
		AnimationTracks.Equip:Stop()
		AnimationTracks.Idle:Stop()
		if AnimationTracks.Swings.Combo ~= nil then
			AnimationTracks.Swings.Combo:Stop()
		end
		AnimationTracks.Holster:Play()
		
		HandMotor.Part0 = Attribute.Holster.Part0(Character)
		HandMotor.Part1 = Attribute.Holster.Part1(ItemModel.Contents)
	end
end

function MeleeModule:SwingEvent()
	if MeleeModule:CanSwing() then
		MeleeModule:swingStart()
		Events.Swing:FireServer()
		AnimationTracks.Swings.Combo = AnimationTracks.Swings[Combo]
		AnimationTracks.Equip:Stop()
		AnimationTracks.Holster:Stop()
		AnimationTracks.Swings.Combo:Play(nil,nil,Attribute.Swings[Combo].Speed)
		wait(Attribute:GetHitboxLength(Combo)+Attribute.Swings.Cooldown)
		MeleeModule:setCombo()
		MeleeModule:swingEnd()
		MeleeModule:swingDisable()
	end
end

function MeleeModule:ParryEvent(activate)
	if activate then
		if MeleeModule:CanParrying() then
			MeleeModule:parryingStart()
			Events.Parrying:FireServer(true)
			FunctionModule:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
			FunctionModule:PlayerControl(false,PlayerConfigs,{WalkSpeed = ServerConfigs.Melee.parryWalkSpeed})
			Humanoid:UnequipTools()
			AnimationTracks.Equip:Stop()
			if AnimationTracks.Swings.Combo ~= nil then
				AnimationTracks.Swings.Combo:Stop()
			end
			AnimationTracks.Parry:Play()
			wait(0.5)
			Events.Parrying:FireServer(false,false)
			wait(1)
			FunctionModule:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
			FunctionModule:PlayerControl(true,PlayerConfigs,{WalkSpeed = ServerConfigs.NormalWalkSpeed})
			AnimationTracks.Parry:Stop()
			MeleeModule:parryingEnd()
			wait(3)
			MeleeModule:parryingDisable()
		end
	else
		Events.Parrying:FireServer(false,false)
		FunctionModule:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
		FunctionModule:PlayerControl(true,PlayerConfigs,{WalkSpeed = ServerConfigs.NormalWalkSpeed})
		AnimationTracks.Parry:Stop()
		MeleeModule:parryingEnd()
		wait(1)
		MeleeModule:parryingDisable()
	end
end

function MeleeModule:DazedEvent()
	FunctionModule:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
	FunctionModule:PlayerControl(false,PlayerConfigs,{WalkSpeed = ServerConfigs.Melee.dazedWalkSpeed})
	Humanoid:UnequipTools()
	AnimationTracks.Equip:Stop()
	if AnimationTracks.Swings.Combo ~= nil then
		AnimationTracks.Swings.Combo:Stop()
	end
	AnimationTracks.Dazed:Play()
	wait(3.5)
	FunctionModule:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
	FunctionModule:PlayerControl(true,PlayerConfigs,{WalkSpeed = ServerConfigs.NormalWalkSpeed})
	AnimationTracks.Dazed:Stop()
end

function MeleeModule:Movement()
	local position = math.asin(Mouse.Hit.LookVector.Y/1.25)
	Events.Arm:WaitForChild("Movement"):FireServer(position)
end

Character.ChildAdded:Connect(function(child)
	if child:IsA("Tool") then
		if MeleeModule:IsItem(child) then
			MeleeModule:EquipEvent(child)
		end
	end
end)

Character.ChildRemoved:Connect(function(child)
	MeleeModule:UnequipEvent(child)
end)

RunService.RenderStepped:Connect(function()
	MeleeModule:Movement()
end)

return MeleeModule

This script is a module for operating melee weapons.

1 Like

So what’s the error? Add a debug.trackback() to your loading module script so you can track those errors. I’m not sure if you added any error handling to your module loader so you might want to wrap the loading part in a pcall().

1 Like