I want to make it so that when the player lands a killing blow on an NPC their specific limb gets dismembered depending on the last part that got hit (madness combat style)
the problem:
I don’t know how to get a reference to that specific part
here's my code and what it currently do (you probably don't need to see this but I'll include it anyway)
-- service
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
-- variable
local tool = script.Parent
local Damage = 35
local Debounce = false
local AttackStep = 1
-- Animation stuff
local Idle = Instance.new("Animation")
Idle.AnimationId = "rbxassetid://82389743504697"
local Slash1 = Instance.new("Animation")
Slash1.AnimationId = "rbxassetid://117195817124320"
local Slash2 = Instance.new("Animation")
Slash2.AnimationId = "rbxassetid://81801466608249"
local Stab = Instance.new("Animation")
Stab.AnimationId = "rbxassetid://116820019801079"
local IdleTrack = nil
local SlashTrack1 = nil
local SlashTrack2 = nil
local StabTrack = nil
-- Creating a hitbox using RaycastHitboxV4 (credit to owner of the module, very cool)
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)
local ignore = {player}
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {ignore}
Params.FilterType = Enum.RaycastFilterType.Exclude
local newHitbox = RaycastHitbox.new(script.Parent)
newHitbox.RaycastParams = Params
for i, v in pairs(tool:GetDescendants()) do
if v.Name == "GrabBox" then
table.insert(ignore, v)
end
end
newHitbox.OnHit:Connect(function(Hit)
if Hit.Parent:FindFirstChildOfClass("Humanoid") then
Hit.Parent.Humanoid:TakeDamage(Damage)
end
end)
-- basic tool stuff
tool.Equipped:Connect(function()
tool.Model.Anchored = false
IdleTrack = script.Parent.Parent.Humanoid:LoadAnimation(Idle)
IdleTrack.Priority = Enum.AnimationPriority.Idle
IdleTrack.Looped = true
IdleTrack:Play()
end)
tool.Unequipped:Connect(function()
if IdleTrack then
IdleTrack:Stop()
end
end)
tool.Activated:Connect(function()
if Debounce == true then
return
else
Debounce = true
if AttackStep == 1 then
SlashTrack1 = script.Parent.Parent.Humanoid:LoadAnimation(Slash1)
SlashTrack1.Priority = Enum.AnimationPriority.Action
SlashTrack1.Looped = false
SlashTrack1:Play()
AttackStep = 2
SlashTrack1:GetMarkerReachedSignal("StartHit"):Connect(function(paramString)
newHitbox:HitStart()
end)
SlashTrack1:GetMarkerReachedSignal("StopHit"):Connect(function(paramString)
newHitbox:HitStop(2)
end)
SlashTrack1:GetMarkerReachedSignal("Interuptable"):Connect(function(paramString)
Debounce = false
end)
elseif AttackStep == 2 then
SlashTrack2 = script.Parent.Parent.Humanoid:LoadAnimation(Slash2)
SlashTrack2.Priority = Enum.AnimationPriority.Action
SlashTrack2.Looped = false
SlashTrack2:Play()
AttackStep = 3
SlashTrack2:GetMarkerReachedSignal("StartHit"):Connect(function(paramString)
newHitbox:HitStart()
end)
SlashTrack2:GetMarkerReachedSignal("StopHit"):Connect(function(paramString)
newHitbox:HitStop(2)
end)
SlashTrack2:GetMarkerReachedSignal("Interuptable"):Connect(function(paramString)
Debounce = false
end)
elseif AttackStep == 3 then
StabTrack = script.Parent.Parent.Humanoid:LoadAnimation(Stab)
StabTrack.Priority = Enum.AnimationPriority.Action
StabTrack.Looped = false
StabTrack:Play()
AttackStep = 1
StabTrack:GetMarkerReachedSignal("StartHit"):Connect(function(paramString)
newHitbox:HitStart()
end)
StabTrack:GetMarkerReachedSignal("StopHit"):Connect(function(paramString)
newHitbox:HitStop(2)
end)
StabTrack.Stopped:wait()
Debounce = false
end
end
end)
-- when drop a tool and after a few second, anchore the part to prevent it from getting fling around while player is moving
tool.AncestryChanged:Connect(function(child, parent)
if parent == workspace then
tool.Model.CanCollide = true
wait(2)
tool.Model.Anchored = true
end
end)