I’m trying to add an animation to whenever you punch a character.
Whenever I try to load an animation in Roblox Studio I get this simple error.
I tried looking for solutions in all places, like the DevForum, StackOverflow, and some others, but I couldnt find any useful information so I hope that making a post will help.
Any and all animation assets are not loading whatsoever, and just a reminder I am fairly new to anything animation related, so if there are any ways I can load this animation using just the ID or anything related to that, that would be great. Also I tried making my own animation, to test if it was just a prioritized user system, but it didnt work with my asset either.
- Main Portion of Error
local AssetService = game:GetService("AssetService")
local punchAnims = {
15359303976, --1
}
local animCoolDown = false
local punchCoolDown = false
local currentAnim = 1
local function play_anim()
-- Inside your loop where you set up the animation:
local animationUrl = punchAnims[currentAnim]
--local success, assetId = pcall(function()
local assetId = AssetService:GetAssetId(animationUrl)
--end)
--if success then
local animator = Instance.new("Animator")
animator.Parent = d_HUM
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = "rbxassetid://" .. tostring(assetId)
local animationTrack = animator:LoadAnimation(kickAnimation)
animationTrack:Play()
print("Animation started")
currentAnim = currentAnim + 1
--else
-- print(tostring(animationUrl))
-- error("Failed to get asset ID for animation:", tostring(animationUrl), assetId)
--end
end
- Entire Script
local p = script.Parent
local dummy = p.Parent -- GETS DUMMY
local d_HUM = dummy.Humanoid
local d_HRP = dummy.HumanoidRootPart -- GETS HUMANOID ROOT PART
local AssetService = game:GetService("AssetService")
local punchAnims = {
15359303976, --1
}
local animCoolDown = false
local punchCoolDown = false
local currentAnim = 1
local function play_anim()
-- Inside your loop where you set up the animation:
local animationUrl = punchAnims[currentAnim]
--local success, assetId = pcall(function()
local assetId = AssetService:GetAssetId(animationUrl)
--end)
--if success then
local animator = Instance.new("Animator")
animator.Parent = d_HUM
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = "rbxassetid://" .. tostring(assetId)
local animationTrack = animator:LoadAnimation(kickAnimation)
animationTrack:Play()
print("Animation started")
currentAnim = currentAnim + 1
--else
-- print(tostring(animationUrl))
-- error("Failed to get asset ID for animation:", tostring(animationUrl), assetId)
--end
end
local function animation_handler()
if not punchCoolDown then
if currentAnim <= #punchAnims then
animCoolDown = true
play_anim()
currentAnim += 1
wait(0.05)
animCoolDown = false
for i=1,10 do
if animCoolDown == true then
return
end
wait()
end
currentAnim = 1
else
punchCoolDown = true
wait(0.75)
currentAnim = 1
punchCoolDown = false
end
end
end
local function front_hitbox()
local overlapParams = OverlapParams.new()
local hitContents = workspace:GetPartBoundsInBox(d_HRP.CFrame*CFrame.new(0,0,-3.5), Vector3.new(7, 6, 8), overlapParams)
local charList = {}
animation_handler()
for i,v in pairs(hitContents) do
local char = v.Parent
local hum = char:FindFirstChild("Humanoid")
if hum and not table.find(charList, char.Name) and hum.Parent ~= dummy then
hum:TakeDamage(10)
table.insert(charList, char.Name)
end
end
end
local function check_input(plr, input)
if input == Enum.KeyCode.E then
if not punchCoolDown then
front_hitbox()
end
end
end
p.SendInput.OnServerEvent:Connect(check_input)