I want the script to load an attack animation when the player activates the sword
local player = game.Players.LocalPlayer
local Char = player.Character
local Humanoid = Char:WaitForChild("Humanoid")
-- Error happens here
local AttackAnim = Humanoid:LoadAnimation(SECRET)
AttackAnim.Priority = Enum.AnimationPriority.Action
AttackAnim.Looped = false
local OneShot = Humanoid:LoadAnimation(SECRET)
OneShot.Priority = Enum.AnimationPriority.Action
OneShot.Looped = false
local Sword = script.Parent
local blade = Sword.Handle.Blade
local Cooldown = 2 -- in seconds
local db = true
Sword.Activated:Connect(function()
if db then
db = false
AttackAnim:Play()
blade.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
if hit.Parent:GetAttribute("Enemy") then
hit.Parent.Humanoid.Health -= 10
print(hit.Parent.Humanoid)
end
end
end)
end
wait(Cooldown)
db = true
end)
I have tried to find a solution in the documentation and the forum but they all said I had to use :Waitforchild() however I’ve already done this
‘’’
local Players = game:GetService(“Players”)
local tool = script.Parent
local animID = “rbxassetid://10884223876” --Variable for animation ID
for i, v in pairs(Players:GetChildren()) do
local player = v
local char = v.Character or v.CharacterAdded:Wait() – Ensure character is loaded
local h = char:WaitForChild(“Humanoid”) – Correct WaitForChild usage
-- Create an Animation object
local animation = Instance.new("Animation")
animation.AnimationId = animID -- Set the AnimationId property
-- Load the animation using the Animation object
local AttackAnim = h:LoadAnimation(animation)
AttackAnim.Priority = Enum.AnimationPriority.Action
AttackAnim.Looped = false
local OneShot = h:LoadAnimation(animation)
OneShot.Priority = Enum.AnimationPriority.Action
OneShot.Looped = false
local Sword = script.Parent
local blade = Sword.Handle
local Cooldown = 2 -- in seconds
local db = true
Sword.Activated:Connect(function()
if db then
db = false
AttackAnim:Play()
blade.Touched:Connect(function(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
if hit.Parent:GetAttribute("Enemy") then
hit.Parent.h.Health -= 10
print(hit.Parent.h)
end
end
end)
end
wait(Cooldown)
db = true
end)