This wouldn’t work like you expect it to, since Character.Humanoid
produces an error if the Humanoid isn’t present. Also, don’t wait on a loop, use events.
yes but the character will still be parent to nil so it wont work
So if the character doesn’t exist, then the script won’t work. This would be beyond me, it could be a bug.
You can do that too, but you should account for when the tool is dropped and picked up by a different player though. Using AncestryChanged, detect which Humanoid owns the tool (even if it’s in the Backpack) and if that changes, clear the stabAnimTrack
.
Edit: Just realized that this is probably in a LocalScript. So, moot point.
i dont plan on having my tool drop
what you said made me think of somthing i can load the animation if player equit it and save it so it only run once
the player is bild in nil then parented to workspace this why you can grab it but it error since loadanimation will only work if the character humanoid is in the workspace
That would’ve been important to mention. In that case, just wrap the load with this:
if not stabAnimTrack then
-- ... load it ...
end
Actually, come to think of it, LoadAnimation already caches its result I think, so there’s really no point in fussing over it. Should work either way!
try to do this
local AnimationFolder = ReplicatedStorage:WaitForChild("AnimationFolder")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:wait()
while Character.Parent == nil do
Character.AncestryChanged:wait()
end
local Humanoid = Character:WaitForChild("Humanoid")
repeat task.wait() until Humanoid
local Stab = Humanoid:WaitForChild("Animator"):LoadAnimation(AnimationFolder.Stab)
That repeat task.wait() until Humanoid
will yield indefinitely if Humanoid
is nil, no matter what. WaitForChild
already does what you expect it to.
shouldn’t a simple :WaitForChild(“Character”) do the trick?
no you want wait for child the character
Hey, kinda late, but I had the same issue. I managed to fix it. Add this to the Tool.Equipped event.
Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
Humanoid = Character:WaitForChild("Humanoid")
Stab = Humanoid:WaitForChild("Animator"):LoadAnimation(AnimationFolder.Stab)
If this won’t fix the problem, then add task.wait()
to the top of the script. I don’t like using this, but if it fixes your problem…