I have a punch tool in my game that does damage to a player when they are hit. I am attempting to make it play a random animation on the player that is hit, but if I make it choose from 3 random animations, it also makes the tool activate multiple times and does way more damage than it should (It should do 10, it instant kills most the time assuming due to the math.random for some reason affecting it). Is this fixable or is it something with my punch script that I need to re-code? I will include the full onTouched function below, hopefully that is enough to go off of.
AssetIDs = {5163743763,5163826438,5163829485}
function onTouched(part)
if part:IsDescendantOf(Tool.Parent) then return end
if not HitAble then return end
if part.Parent and part.Parent:FindFirstChild("Humanoid") then
local human = part.Parent.Humanoid
if contains(HitVictims, human) then return end
local root = part.Parent:FindFirstChild("HumanoidRootPart")
if root and not root.Anchored then
local myRoot = Tool.Parent:FindFirstChild("HumanoidRootPart")
if myRoot and checkTeams(human) then
local delta = root.Position - myRoot.Position
tagHuman(human)
--// Animation Start
local hitAnimation = Instance.new("Animation")
hitAnimation.AnimationId = "rbxassetid://"..math.random(1, #AssetIDs)
local hitAnimationTrack = human:LoadAnimation(hitAnimation)
--// Animation End
human:TakeDamage(HitDamage)
wait(.3)
hitAnimationTrack:Play()
table.insert(HitVictims, human)
end
end
end
end