For some reason after my function finishes, the npc turns into parts. I think it has something to do with my weldconstraint.
local hum = script.Parent:WaitForChild("Humanoid")
local anim = hum:LoadAnimation(script.Parent.Eat)
while anim.Length <= 0 do task.wait() end
script.Parent.Hitbox.Touched:Connect(function(touch)
if not touch.Parent:FindFirstChild("Humanoid") then return end
local Char = touch.Parent
if Char:FindFirstChild("Titan") then return end
if not game.Players:FindFirstChild(Char.Name) then return end
if script.Parent.InAttack.Value == false then
script.Parent.InAttack.Value = true
-- Char.HumanoidRootPart.Anchored = true
Char.RightHand.CFrame = script.Parent.Hitbox.CFrame
local weld = Instance.new("WeldConstraint")
weld.Parent = Char
weld.Part0 = Char.HumanoidRootPart
weld.Part1 = script.Parent.Hitbox
anim:Play()
anim.Stopped:wait()
weld:Destroy()
Char.Humanoid.Health = 0
script.Parent.InAttack.Value = false
end
end)
local hum = script.Parent:WaitForChild(“Humanoid”)
local anim = hum:LoadAnimation(script.Parent.Eat)
while anim.Length <= 0 do task.wait() end
script.Parent.Hitbox.Touched:Connect(function(touch)
if not touch.Parent:FindFirstChild(“Humanoid”) then return end
local Char = touch.Parent
if Char:FindFirstChild("Titan") then return end
if not game.Players:FindFirstChild(Char.Name) then return end
if script.Parent.InAttack.Value == false then
script.Parent.InAttack.Value = true
-- Char.HumanoidRootPart.Anchored = true
Char.RightHand.CFrame = script.Parent.Hitbox.CFrame
local weld = Instance.new("WeldConstraint")
weld.Parent = Char
weld.Part0 = Char.HumanoidRootPart
end
local hum = script.Parent:WaitForChild(“Humanoid”)
local anim = hum:LoadAnimation(script.Parent.Eat)
while anim.Length <= 0 do task.wait() end
script.Parent.Hitbox.Touched:Connect(function(touch)
if not touch.Parent:FindFirstChild(“Humanoid”) then return end
local Char = touch.Parent
if Char:FindFirstChild("Titan") then return end
if not game.Players:FindFirstChild(Char.Name) then return end
if script.Parent.InAttack.Value == false then
script.Parent.InAttack.Value = true
-- Char.HumanoidRootPart.Anchored = true
Char.RightHand.CFrame = script.Parent.Hitbox.CFrame
local weld = Instance.new("WeldConstraint")
weld.Parent = Char
weld.Part0 = Char.HumanoidRootPart
weld.Part1 = script.Parent.Hitbox
anim:Play()
anim.Stopped:wait()
script.Parent.InAttack.Value = false
end
local hum = script.Parent:WaitForChild(“Humanoid”)
local anim = hum:LoadAnimation(script.Parent.Eat)
while anim.Length <= 0 do task.wait() end
script.Parent.Hitbox.Touched:Connect(function(touch)
if not touch.Parent:FindFirstChild(“Humanoid”) then return end
local Char = touch.Parent
if Char:FindFirstChild("Titan") then return end
if not game.Players:FindFirstChild(Char.Name) then return end
if script.Parent.InAttack.Value == false then
script.Parent.InAttack.Value = true
-- Char.HumanoidRootPart.Anchored = true
Char.RightHand.CFrame = script.Parent.Hitbox.CFrame
local weld = Instance.new("WeldConstraint")
weld.Parent = Char
weld.Part0 = Char.HumanoidRootPart
weld.Part1 = script.Parent.Hitbox
anim:Play()
anim.Stopped:wait()
weld:Destroy() Script.Parent.Humanoid.MaxHealth(onTouched) = 0
I would like to clarify that Char is the player the npc is attacking, not the npc itself. Now all of a sudden the npc isn’t breaking without doing anything which is weird. I believe it might have something to do with it tho.
local hum = script.Parent:WaitForChild("Humanoid")
local anim = hum:LoadAnimation(script.Parent:WaitForChild("Eat"))
while anim.Length <= 0 do task.wait() end
local hitbox = script.Parent:WaitForChild("Hitbox")
local inAttack = script.Parent:WaitForChild("InAttack")
hitbox.Touched:Connect(function(touch)
if touch.Parent:FindFirstChild("Accessory") then
local character = touch.Parent
if character:FindFirstChild("Titan") then
return
end
if not inAttack.Value then
inAttack.Value = true
character:WaitForChild("RightHand").CFrame = hitbox.CFrame
local weld = Instance.new("WeldConstraint")
weld.Parent = workspace
weld.Part0 = character:WaitForChild("HumanoidRootPart")
weld.Part1 = hitbox
anim:Play()
anim.Stopped:Wait()
weld:Destroy()
character.Humanoid.Health = 0
task.wait(1)
inAttack.Value = false
end
end
end)
Make sure the NPC isn’t triggering its own “Touched” event since it will also have a child instance named “Humanoid”. Use a player unique instance instead, “Accessory” for example.