Help with tool, localscript and humanoid

I have a tool with a local script inside. The local script finds the character humanoid and loads animations into it.

When first spawning it works just fine, but when respawning it quits working. It seems to index the humanoid of the first character rather than the new, second one.

--Localscript inside of the tool. Original tool is in StarterPack.
--Code is simplified.

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local function LoadAnimation(Anim)
	local Success, Returned
	
	print("Loading Animation '" .. Animation.AnimationId .."'...")
	
	while not Success do
		Success, Returned = pcall(function()
			-- I need to check this cos or else the AnimationClipProviderService error occurs.
			if not Humanoid:IsDescendantOf(workspace) then
				error("Humanoid isn't in workspace.")
			end
			
			return Humanoid:LoadAnimation(Animation)
		end)
		if not Success then
			print("Fail:", Returned)
			task.wait(1)
		else
			print("Success.")
		end
	end
	
	return Returned
end

LoadAnimation(script:WaitForChild("MyAnim"))

Here is the output:

(Character Spawns)

Loading Animation ‘[anim id here]’
Success.

(Character dies, then respawns)

Loading Animation ‘[anim id here]’
Fail: Humanoid isn’t in workspace. (repeats forever)

If you need more info, just ask.

Whenever a character dies a new version of them is creating the way to keep the old character is to disable CharacterAltoLoads and make your own character spawn system

Fixed it. Oops 3030303030303030303030

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.