LoadAnimation required humanoid object to be a descendant of game object..?


Any idea what’s causing this?
CODE:

local Animation = Instance.new('Animation', script)
Animation.Name = "MedKitAnimation"
Animation.AnimationId = "rbxassetid://4914943902"

local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Equipped = false

local Humanoid = Character:WaitForChild('Humanoid')


function OnEquip()
	Equipped = true
end

function OnUnquip()
	Equipped = false
end

Mouse.Button1Down:Connect(function()
	if Equipped and Humanoid.Health <= 199 then
		local LoadedAnimation = Humanoid:LoadAnimation(Animation)
		LoadedAnimation:Play()
		delay(3, function()
			if Equipped == true then
			
				game.ReplicatedStorage.OOP.MedKit:FireServer("4a29123ksahjgjmlw.d/a.awdWI34$$%")
				for i,v in ipairs(Humanoid:GetPlayingAnimationTracks()) do
					if v.Name == "MedKitAnimation" then
						v:Stop()
						end
					end
				Equipped = false
				script.Parent:Destroy()
					Humanoid:UnequipTools()
				end
				
			end)
				
	end
end)

script.Parent.Equipped:Connect(OnEquip)
script.Parent.Unequipped:Connect(OnUnquip)

Don’t do

local Character = Player.Character or Player.CharacterAdded:Wait()

But do

local Character = Player.Character

Please search before posting. When you respawn, a new instance of your character is created. So your code is referring to the old humanoid. Hence the message, it requires a humanoid in-game. But the old humanoid is now in nil.

1 Like