So I've been playing around with module scripts recently and I've tried making a basic sword attack where when the hitbox of the sword connects it tells a module to calculate the damage. This way, I don't have to manually change each and every sword if there needs to be an update in the future.
The issue though is that the touched event I'm running will say that it runs the full code, but the module then will not run, except for only sometimes. Therefore only dealing damage sometimes. The damage patterns appear to be random.
Serverscript (prints "Works" all the time):
local combatScript = require(game.ServerScriptService.combatModule) local char = script.Parent.Parent.Parent local plrs = game:GetService("Players") local plr = plrs:GetPlayerFromCharacter(char) local alreadyHit = {} script.Parent.Touched:Connect(function(toucher) if toucher.Parent:FindFirstChild("Humanoid") then local isThere = table.find(alreadyHit, toucher.Parent) if not isThere then table.insert(alreadyHit, toucher.Parent) combatScript.lightAttack(plr, toucher) print("Works") end end end) char:WaitForChild("attacking"):GetPropertyChangedSignal("Value"):Connect(function() if char.attacking.Value == false then table.clear(alreadyHit) end end)
Module (Prints "will run" only sometimes, but completes the function normally when it does):
function combatHandler.lightAttack(atkPlr, toucher) print("Will Run") if toucher.Parent:FindFirstChild("Humanoid") and atkPlr.Character.attacking.Value == true then local atkChar = atkPlr.Character local parried = false local char = toucher.Parent local plr = plrs:GetPlayerFromCharacter(char) --For Players if plr then else --For Doomborne end --Now damage management if char.parrying.Value == true then --For the Defending Player char.timesParried.Value += 1 --Focus Calculation if char.timesParried.Value > 1 and char.inFocus.Value == false then char.focus.Value += 1 if char.focus.Value >= 5 then char.inFocus.Value = true end end --When Animations are done, add playing them here elseif char.Humanoid.Health > 1 then print("They're up still") local damageCalculation = char.Humanoid.Health - atkPlr.Character:FindFirstChildWhichIsA("Tool").baseDamage.Value if damageCalculation < 1 then print("Down to 1") char.Humanoid.Health = 1 char.Humanoid.Sit = true --Add Knocked Animation else char.Humanoid:TakeDamage(atkPlr.Character:FindFirstChildWhichIsA("Tool").baseDamage.Value) print("Damage Dealt") end end end end
Is this a problem with my code? Or is this a bug with module scripts right now?
I found the problem. The attacking value was set to false way too early. 0-o