Hello. I was trying to port over my server script which handles the punching to a module script; so that I can make the system easier to add on NPCs and such. However I encountered an error which I’m not able to debug at all, which is why I’m posting this here.
This is a snippet of the code that’s causing the issue, as the rest isn’t important to the issue:
Combat.__index = Combat
function Combat.SetCombat()
return setmetatable({
Damage = 5,
StunDuration = .5,
Character = nil,
FX = nil,
HitboxSize = Vector3.new(4,4,4),
StartTime = .16,
StopTime = .25,
Offset = CFrame.new(0,0,-2.5),
MaxCombo = 4
}, Combat)
end
function Combat:Attack(player)
local character = self.Character
local humanoid = character:FindFirstChild("Humanoid")
It is then executed in a serverscript:
local punch = game.ReplicatedStorage:WaitForChild("PunchingEvent")
punch.OnServerEvent:Connect(function(player)
local ServerStorage = game:GetService("ServerStorage")
local BasicCombat = require(ServerStorage.Modules.BasicCombat)
local combat = BasicCombat.SetCombat()
combat.Character = player.Character
print(player.Character)
combat.FX = vfx
BasicCombat:Attack()
end)
The issue here is that Roblox Studio refuses to recognize the variables from the table, and recognizes them randomly.
The variables it recognizes are those:
- StopTime (not the StartTime)
- MaxCombo
- Offset
- HitboxSize
It also seems like if I delete one of those variables from the table, Roblox still recognizes them as if they exist.
The error given is when the Humanoid is attempted to be found, as even though the ServerScript defines the player character, the module script for some reason decides to ignore it.
Here’s the error line:
ServerStorage.Modules.BasicCombat:59: attempt to index nil with 'FindFirstChild' - Server - BasicCombat:59
Any help is appreciated