My hitbox script won’t ALWAYS damage the NPC. And when it does, the hitbox doesn’t do the specified amount of damage. It “chooses” to deal 15-20 damage to the NPC’s humanoid. To add onto that, when the NPC dies it gives them MORE than the specified amount! Similar to the damage bug. I am thinking of using GetPartsInPart() instead of .Touched, let me know if I should do so. All help is appreciated!
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local db = false
local plrs = game:GetService("Players")
local plr = plrs:GetPlayers()[1] or plrs.PlayerAdded:Wait()
script.Parent.HitBoxEvent.OnServerEvent:Connect(function()
if db then return end
db = true
local Hitbox = Instance.new("Part")
Hitbox.Parent = script.Parent.Parent
Hitbox.CFrame = script.Parent.Parent.HumanoidRootPart.CFrame * CFrame.new(0, 0, .5)
Hitbox.Transparency = .4
Hitbox.Anchored = false
Hitbox.Size = Vector3.new(7, 7, 5)
Hitbox.CanCollide = false
Hitbox.Touched:Connect(function(hit)
local npc = hit.Parent:FindFirstChild("NPC")
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if npc and humanoid then
humanoid:TakeDamage(1)
if humanoid.Health <= 0 then
local leaderstats = plr:FindFirstChild("leaderstats")
if leaderstats and leaderstats:FindFirstChild("Coins") then
leaderstats.Coins.Value = leaderstats.Coins.Value + 1
end
end
end
end)
game.Debris:AddItem(Hitbox, 0.1)
wait(0.3)
db = false
end)