local finalSlashAnim = plr.Character.Humanoid.Animator:LoadAnimation(finalSlashAnimation)
finalSlashAnim:Play()
local validPlayers = game.Players:GetPlayers()
local connection --setting up connection variable to be used later
local function finalSlashHitDetectionFunction(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= "clone" then
--deal damage to hit
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - finalSlashDamage
--removal from validPlayers list
if game.Players:GetPlayerFromCharacter(hit.Parent) then --if it is in fact a player
--first use table.find to get their index
local index = table.find(validPlayers, game.Players:GetPlayerFromCharacter(hit.Parent))
--remove them from the list
table.remove(validPlayers, index)
end
end
end
finalSlashAnim:GetMarkerReachedSignal("superSlashEffectTrigger"):Connect(function()
--disable player collisions, add trails and/or fire to every part of their body
--connect damage function, make them zoom forward, sfx
--disable player collisions
for i, part in pairs(plr.Character:GetDescendants()) do
if part.ClassName == "Part" then
physicsServ:SetPartCollisionGroup(part, "finalSlashUser")
end
end
--adding hitbox to player
local boxOrientation, boxSize = plr.Character:GetBoundingBox()
local hitBox = Instance.new("Part")
hitBox.CanCollide = false
hitBox.Transparency = 1
hitBox.Massless = true
hitBox.Size = boxSize
hitBox.Name = "finalSlashHitBox"
hitBox.Parent = plr.Character
--welding to humanoidRootPart
local hitBoxWeld = Instance.new("ManualWeld")
hitBoxWeld.Part0 = plr.Character.HumanoidRootPart
hitBoxWeld.Part1 = hitBox
hitBoxWeld.Parent = hitBoxWeld.Part0
--connect damage function
connection = plr.Character.finalSlashHitBox.Touched:Connect(finalSlashHitDetectionFunction)
--zoom forward
local velocity = Instance.new("BodyVelocity")
velocity.Name = "finalSlashVelocity"
velocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
velocity.Velocity = plr.Character.HumanoidRootPart.CFrame.LookVector * 200
velocity.Parent = plr.Character.HumanoidRootPart
end)
finalSlashAnim:GetMarkerReachedSignal("superSlashStop"):Connect(function()
--enable player collisions, delete all trails/fire, disconnect damage function
--unfreeze player, enable inventory, trigger cooldown stuff and all that
--delete velocity
if plr.Character.HumanoidRootPart:FindFirstChild("finalSlashVelocity") then
plr.Character.HumanoidRootPart.finalSlashVelocity:Destroy()
end
--enable player collisions
for i, part in pairs(plr.Character:GetDescendants()) do
if part.ClassName == "Part" then
physicsServ:SetPartCollisionGroup(part, "players")
end
end
--disconnect damage function
connection:Disconnect()
--wait until the end of the animation, because there needs to be a dramatic pause
finalSlashAnim.Stopped:Wait()
--delete hitbox
if plr.Character:FindFirstChild("finalSlashHitBox") then
plr.Character.finalSlashHitBox:Destroy()
end
All of this is in a server script, in a remote event.
Everything works fine except the hit detection part. I’ve deleted everything I deemed to be irrelevant.
But yeah, every part of this works except hit detection. The touched event is never fired.
Edit: I even changed it so that the hit script is simply “hit:Destroy()”. Even this doesn’t work except once in a blue moon for some reason…