Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

why do my animations not load on the humanoid?

Asked by 3 years ago
Edited 3 years ago

so I have this dead by daylight-esk hook model that locks a target in place, waits a bit, and then lets them "struggle" to break the hook. there are 3 animations in place for this: hooking, idle, and struggling

what I'm currently doing:

local target = script:WaitForChild(plr).Value -- I use a stringvalue object to store the player name, this makes a bit more sense in the grand scheme of my setup
target.HumanoidRootPart.Anchored = true
target.HumanoidRootPart.CFrame = workspace.Hook.Tele.CFrame
target.Humanoid:LoadAnimation(game.Workspace.Hook.idle):Play() -- the animation I wanna play here

why does nothing happen when using this script? I looked up the LoadAnimation function and the dev API says it's deprecated, so what should I use instead? edit: by nothing happening I mean that the animations don't play at all, anchoring the hrp and setting the cframe works totally fine

edit 2: so after the first response I got, this is my code now:

local Character = game:GetService("Workspace")[script.plr.Value]
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid") or Character:WaitForChild("Humanoid")
local Animator = Humanoid:FindFirstChildWhichIsA("Animator")

local idle = script.idle
local idleanim = Animator:LoadAnimation(idle)
local hooked = script.hooked
local hookedanim = Animator:LoadAnimation(hooked)
local struggle = script.struggle
local struggleanim = Animator:LoadAnimation(struggle)

Character.Parent = script.Hook
script.Hook.Tele["music1"]:Play()
Character.HumanoidRootPart.Anchored = true
Character.HumanoidRootPart.CFrame = script.Hook.Tele.CFrame


idleanim:Play()
wait(0.1)

script.Hook.Part.scream:Play()

hookedanim:Play()

as you can see I now use the "Animator" instance in the player, define variables for each of the animations and then call :Play() on them when needed, but this still does not work. the animation just doesn't seem to play. there's nothing wrong with the Animation object in the script or the animation id, it plays fine in the btroblox preview on the website. I'm truly lost here

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

Humanoid.LoadAnimation is deprecated, use Animator.LoadAnimation instead.

I would also suggest placing the idle Instance in the script & defining it with script:WaitForChild("idle"). This script below expects you to already have the Character variable defined.

local Humanoid = Character:FindFirstChildWhichIsA("Humanoid") or Character:WaitForChild("Humanoid")
local Animator = Humanoid:FindFirstChildWhichIsA("Animator")

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://0" -- Your animation id here.
Animation.Parent = script

local AnimationTrack = Animator:LoadAnimation(Animation)

Here are some useful sources to get you started on playing animations with characters. https://developer.roblox.com/en-us/api-reference/class/AnimationController https://developer.roblox.com/en-us/api-reference/class/AnimationTrack

0
i tried this and added the Play() functions at the proper times, read my edit and see if i did anything wrong QuirkyAnimeBoy 0 — 3y
Ad

Answer this question