local Tool = script.Parent
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")
local Stab = Humanoid:WaitForChild("Animator"):LoadAnimation(AnimationFolder.Stab)
i use
while Character.Parent == nil do
Character.AncestryChanged:wait()
end
to try to get around the issue where you cant load animation if your character is not in the workspace but it seam to just wait for ever I try other methods and print the character parent it will tell me its nil even do my character is in the workspace
the isue is that to use LoadAnimation the humanoid need to be descendent of workspace but I put the tool in the backpack and ig the script run before the game load my character in so i made a loop to wait for character but all the loop i try make always tell me the character parent is nil even do I’m in the game
Something can have a parent yet still not be a descendant of workspace. Try this:
while not Character:IsDescendantOf(workspace) do
Character.AncestryChanged:Wait()
end
Debugging tip: For the sake of debugging, you could print GetFullName on the character before each wait() to inspect what it might be inside.
while not Character:IsDescendantOf(workspace) do
print("Not yet in workspace: ", Character:GetFullName(), Character.Parent)
Character.AncestryChanged:Wait()
end
local Tool = script.Parent
local AnimationFolder = game.ReplicatedStorage:WaitForChild("AnimationFolder")
local LocalPlayer = game.Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
while Character.Parent == nil do
Character.AncestryChanged:Wait()
end
local Stab = Humanoid:WaitForChild("Animator"):LoadAnimation(AnimationFolder.Stab)
Some capitalization, and other things were incorrect. Try this, it might work.
The tool code only grabs a reference to the player’s character once, so if the character changes (ie. the player respawns, maybe even immediately) your tool will still be considering the old character. Since this is a tool, you should load the AnimationTrack when the player equips the tool, as you can just reference the character using Tool.Parent.
local Tool = script.Parent
local AnimationFolder = game.ReplicatedStorage:WaitForChild("AnimationFolder")
local stabAnimTrack = nil
local function onEquipped()
stabAnimTrack = Tool.Parent.Humanoid:LoadAnimation(AnimationFolder.Stab)
end
local function onUnequipped()
stabAnimTrack = nil
end
Tool.Equipped:Connect(onEquipped)
Tool.Unequipped:Connect(onUnequipped)