This should work right? But it’s not. The script is local in a tool. The damage bit works but not the animation.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = script.Parent.Animation
local loadedAnimation
if humanoid then
if animation then
loadedAnimation = humanoid.Animator:LoadAnimation(animation)
end
end
local debounce = false
script.Parent.Activated:Connect(function()
if not debounce then
print("activated")
debounce = true
if loadedAnimation then
loadedAnimation:Play()
end
wait(0.5)
debounce = false
end
end)
script.Parent.Handle.Touched:Connect(function(hit)
local model = hit.Parent
if model then
if model:FindFirstChildOfClass("Humanoid") and not debounce then
model.Humanoid.Health -= 25
end
end
end)
Is there any purpose in the animator you used from humanoid? I saw you put humanoid.Animator:LoadAnimation(). Could just humanoid:LoadAnimation() be the easy fix?
There are also many problems with the script that could affect the result.
I fixed some of them:
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildOfClass("Humanoid")
local animation = script.Parent:FindFirstChild("Animation")
local Animator = humanoid:FindFirstChildOfClass("Animator")
local loadedAnimation
if humanoid and Animator and animation then
loadedAnimation = Animator:LoadAnimation(animation)
end
script.Parent.Activated:Connect(function()
if Tool.Enabled then
Tool.Enabled = false
if loadedAnimation then
loadedAnimation:Play()
end
task.wait(0.5)
Tool.Enabled = true
end
end)
Handle.Touched:Connect(function(hit) --This will damage localy. Make sure you damage things with a ServerScript
local model = hit.Parent
if model then
if model:FindFirstChildOfClass("Humanoid") and not Tool.Enabled then
model.Humanoid:TakeDamage(25)
end
end
end)
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local animation = tool:WaitForChild("Animation")
local track = humanoid:LoadAnimation(animation)
local debounce = false
tool.Activated:Connect(function()
if debounce then return end
debounce = true
track:Play()
track.Stopped:Wait()
debounce = false
end)
handle.Touched:Connect(function(hit)
local hitModel = hit:FindFirstAncestorOfClass("Model")
if hitModel then
local hitHuman = hitModel:FindFirstChildOfClass("Humanoid")
if hitHuman then
hitHuman:TakeDamage(25)
end
end
end)
You should also be dealing damage on the server, you can achieve this via a RemoteEvent instance.