Hello there!
I’m working on a Terraria clone game and there is an issue with a sword I’m currently working on. For some reason, it only damages one NPC only. It also seems to damage me if I change the code a bit as seen here:
--//Tool\\--
local Tool = script.Parent
local RemoteEvent = Tool:WaitForChild("RemoteEvent")
--//Func\\--
RemoteEvent.OnServerEvent:Connect(function(plr,Type)
if Type == "SwordHitbox1" then
local Hitbox = Instance.new("Part",workspace)
game:GetService("Debris",0.01)
Hitbox.Size = Vector3.new(4,5,6)
Hitbox.Massless = true
Hitbox.Transparency = 0.5
Hitbox.Anchored = false
Hitbox.CanCollide = false
Hitbox.CFrame = plr.Character.PrimaryPart.CFrame * CFrame.new(0,0, ((Hitbox.Size.Z)/2 + 1) * -1)
local HitboxWeld = Instance.new("WeldConstraint",Hitbox)
HitboxWeld.Part0 = plr.Character.PrimaryPart
HitboxWeld.Part1 = Hitbox
local PartsInsideHitbox = workspace:GetPartsInPart(Hitbox)
for i,v in pairs(PartsInsideHitbox) do
if v.Parent:IsA("Model") and (v.Parent ~= plr) then
local Hits = {}
local Humanoid = v.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid and not Hits[v.Parent] then
Hits[v.Parent] = true
Humanoid:TakeDamage(80)
task.wait(50)
end
end
end
Hitbox:Destroy()
end
end)