NPC Damage Gets Multiplied Every Hit? (RaycastHitboxV2 Module) [SOLVED]
Asked by
4 years ago Edited 4 years ago
Hi, so I am making a game and I was using the raycasthitboxv2 module for the melee hitbox. It works good and all except for the fact that the damage gets multiplied everytime the player swings the weapon. For example the base damage is 5 and if a player swings twice but the first time the swing didnt hit the second time if it did it then the NPC would get damaged for 10 instead of 5, and it just keeps going up by 5 every swing. Any help is appreciated. Heres my code:
03 | local Remotes = replicatedStorage:WaitForChild( "Remotes" ) |
04 | local SwingRemote = Remotes:WaitForChild( "Swing" ) |
05 | local ShovelData = require(game:GetService( "ServerScriptService" ):WaitForChild( "Modules" ):WaitForChild( "ShovelData" )) |
06 | local replicatedData = replicatedStorage:FindFirstChild( "replicatedData" ) |
07 | local NPCFolder = game.Workspace:FindFirstChild( "NPC's" ) |
09 | local RAYCAST_HITBOX = require(replicatedStorage.Modules.RaycastHitboxV 2 ) |
15 | if CanDamage = = true then |
17 | local playerCurrentShovel = replicatedData:WaitForChild(Player.UserId).CurrentShovel.Value |
18 | local Character = Player.Character or Player.CharacterAdded:Wait() |
19 | local Shovel = Character:WaitForChild(playerCurrentShovel) |
20 | local DamageToTake = ShovelData [ playerCurrentShovel ] .Damage |
22 | local newHitbox = RAYCAST_HITBOX:Initialize(Shovel.Handle) |
25 | doDamage(Shovel, newHitbox) |
32 | function doDamage(Shovel, HitBox) |
33 | local Character = Shovel.Parent |
34 | local Player = game.Players:GetPlayerFromCharacter(Character) |
35 | local playerCurrentShovel = replicatedData:WaitForChild(Player.UserId).CurrentShovel.Value |
36 | local DamageToTake = ShovelData [ playerCurrentShovel ] .Damage |
38 | HitBox.OnHit:Connect( function (hit, humanoid) |
39 | if hit.Parent ~ = Character and hit.Parent.Parent = = NPCFolder then |
40 | local hitNpc = hit.Parent.Humanoid |
41 | hitNpc:TakeDamage(DamageToTake) |