Animation wont play, nor errors in the output, its in a local script, inside a tool.
local fist = script.Parent.Parent
fist.Enabled = false
local animation = nil
local punch = nil
local connection
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
function onActivation()
fist.Handle.Touched:connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
local humanoid1 = hit.Parent:FindFirstChild('Humanoid')
local PlayerWhoGotHit = game.Players:GetPlayerFromCharacter(hit.Parent)
animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://8194480087"
punch = humanoid:LoadAnimation(animation)
punch:Play()
humanoid1:TakeDamage(2)
end
end)
connection:Disconnect()
end
connection = fist.Activated:Connect(onActivation)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local handle = script.Parent
local fist = handle.Parent
fist.Enabled = false
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://8194480087"
punch = humanoid:LoadAnimation(animation)
repeat task.wait()
until punch.Length > 0.1
local touchconn = nil
local debounce = false
fist.Activated:Connect(function()
touchconn = handle.Touched:Connect(function(hit)
if debounce then
return
end
if hit.Parent:FindFirstChild("Humanoid") then
debounce = true
local hithumanoid = hit.Parent:FindFirstChild('Humanoid')
local hitcharacter = hit.Parent
local hitplayer = game.Players:GetPlayerFromCharacter(hitcharacter)
punch:Play()
hithumanoid:TakeDamage(2)
end
task.wait(3)
debounce = false
end)
end)
fist.Deactivated:Connect(function()
touchconn:Disconnect()
end)
You probably need a debounce, I’ve also made some other minor optimisations like only loading the animation track once. A single AnimationTrack instance can be played any number of times. You were also using the deprecated “:connect()” method, you also don’t need to disconnect the Activated event as it will only be connected once (per tool lifetime) and is destroyed whenever the tool is destroyed (when the player’s character dies). The Touched event connection on the other hand is created each time the tool is activated and as such should promptly be disconnected whenever the corresponding Deactivated event fires.