Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My emotes gui work at first but after I reset my character it don't work anymore, how to fix it ?

Hi I've made a emote gui which it's very working but after I reset my character the emotes doesn't work anymore and it pops up this error and I haven't figure out how to fix it yet : " Loadanimation requires the humanoid object (player1.Humanoid) to be a descendant of the game object "

Here's my script

wait(1)
local user = game.Players.LocalPlayer
repeat
	wait()
until user.Character
local Input = game:GetService("UserInputService")
local animen = script.Parent.Parent.Parent:WaitForChild("Dances")
local speeder, speedval = animen:WaitForChild("Speeddancehaha"), 1
local mouse = user:GetMouse()
local scrollingframe = script.Parent
local anim
local char = user.Character
local humanoid = char:WaitForChild("Humanoid")
local ftime = 0.7
function playanim(id, lola)
	function setspeedval(num)
		speedval = num
		if anim then
		anim:AdjustSpeed(num)
		end
		speeder.Bar.Size = UDim2.new(num / 2 * 3 - 1, 0, 1, 0)
	end
	speeder.MouseButton1Down:Connect(function()
		while Input:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) and game:GetService("RunService").RenderStepped:Wait() do
			local absz, absp = speeder.AbsoluteSize, speeder.AbsolutePosition
			local fact = math.min(1, math.max(0, (mouse.X - absp.X) / absz.X))
			setspeedval((fact + 1) * 2 / 3)
		end
	end)
	if char ~= nil and humanoid ~= nil then
		local id = "rbxassetid://" .. tostring(id)
		local oldanim = char:FindFirstChild("LocalAnimation")
		if anim ~= nil then
			anim:Stop(ftime / speedval)
		end
		if oldanim ~= nil then
			if oldanim.AnimationId == id then
				oldanim:Destroy()
				return
			end
			oldanim:Destroy()
		end
		local animation = Instance.new("Animation", char)
		animation.Name = "LocalAnimation"
		animation.AnimationId = id
		anim = humanoid:LoadAnimation(animation)
		anim:Play(ftime / speedval)
		if lola then
			setspeedval(lola.Speed)
		end
		anim:AdjustSpeed(speedval)
		function stopdance()
			if not anim then
				return
			end
	    anim:Stop(ftime / speedval)
	    anim = nil
	    speeder.Bar.Size, speedval = UDim2.new(0.5, 0, 1, 0), 1
end
        spawn(function()
	    while wait() do
		local hum = char:FindFirstChild("Humanoid")
		if hum and (hum.Sit or hum.MoveDirection.Magnitude > 0) then
			pcall(stopdance)
		end
	end
end)

Please help me fix this annoying errors

2 answers

It's because you're not re-referencing the character's humanoid. Every time a character dies it destroys that old character and creates a new one, therefore, any references to character or humanoid are nil. You can fix the character like this

local char = player.Character or player.CharacterAdded:Wait() -- This essentially runs and sais if the character then char == character if not then it waits till its added and then it's then the character

The humanoid you could just re-reference every time you call the playanim function like so

function playAnim()
	local humanoid = char.Humanoid or char:WaitForChild("Humanoid") -- This either gets the valid humanoid or waits for a valid humanoid
end

If this answers your question please mark it as answered or an upvote. Good luck!

  • Best Regards, - Syn

7 comments

0

Still not working :(

0

Add some prints and see where it's not working

0

Oh my bad i forgot it's at line 46 - global playanim

0

Ye but thats a whole function with 40 lines it's not the actual problem

0

It's telling you thats theres an error in that function, add prints to find it

0

i couldn't find it, sorry :(

0

I would love to help you but without pinpointing the error I don't know where to start

Try doing LocalScript and doing FireServer, but don't put LocalScript in the gui that doesn't restart when restarting

This discussion is preserved as it was. New answers, comments, and votes are closed.