Help applying animation

I would like to be able to apply the animation according to the emote when clicking the button, but I can’t do it.
I use InsertService to get the emote animation, but I can’t apply the animation to the player

Captura de tela 2024-01-22 201233

local HttpService = game:GetService("HttpService")
local StarterGui = game:GetService("StarterGui")
local InsertService = game:GetService('InsertService')
--
local ScreenGui = StarterGui.HUD
local EmoteFrame = ScreenGui:WaitForChild("EmoteFrame")
--
local URL = "https://catalog.roproxy.com/v1/search/items/details?Category=12&Subcategory=39&salesTypeFilter=1&Limit=30"
local response = HttpService:GetAsync(URL)
local decodedData = HttpService:JSONDecode(response)
--
if decodedData and type(decodedData) == "table" then
	if decodedData.data and type(decodedData.data) == "table" then
		local idsTable = {} 
		--
		for _, item in ipairs(decodedData.data) do
			if type(item) == "table" and item.id then
				table.insert(idsTable, item.id)
			end
		end
		--
		for i,EmotesId in pairs(idsTable) do
			local Emotes = tonumber(EmotesId)
			if Emotes then
				
				local Anim = game:GetService("InsertService"):LoadAsset(EmotesId):GetDescendants()[1]
				
				local Template = script.Template:Clone()
				Template.Parent = EmoteFrame.EmotesContainer.Scrolling
				Template.EmoteID.AnimationId = Anim.AnimationId
				Template.Icon.Image = "http://www.roblox.com/Thumbs/Asset.ashx?Height=256&Width=256&AssetID="..EmotesId
				Template.Visible = true
			end
		end
	end
end
3 Likes

I’m not sure what the EmotesId would be, but you can try just setting the ID to the animationId of an animation instance and then applying it to the humanoid from there instead of using insert service. Something like this:

local anim = Instance.new("Animation")
anim.AnimationId = EmotesId
-- Apply the animation and play it

Reference this to see how to play the animation.

3 Likes

The script is stored in ServerScriptService, I already tried this but it didn’t work. I keep trying to find a solution, but nothing yet.

1 Like

Have you tried attaching rbxassetid:// to the front of the animation id?

The best I could do was print the emote image and its animation id (http://www.roblox.com/asset/?id=14352362059).

I tried that, but… It doesn’t work either

for i, EmotesId in pairs(idsTable) do
			local Emotes = tonumber(EmotesId)
			if Emotes then
				-- Carrega o emote do serviço de inserç��o e o coloca em ReplicatedStorage.AnimEmo
				game.InsertService:LoadAsset(EmotesId).Parent = game.ReplicatedStorage.AnimEmotes
				local AnimEmotes = game.ReplicatedStorage.AnimEmotes:FindFirstChildOfClass("Model"):GetChildren()

				for i, Anim in pairs(AnimEmotes) do
					local Template = script.Template:Clone()
					Template.Parent = EmoteFrame.EmotesContainer.Scrolling
					Template.EmoteID.AnimationId = Anim.AnimationId 
					Template.LocalScript.Enabled = true
					Template.Icon.Image = "http://www.roblox.com/Thumbs/Asset.ashx?Height=256&Width=256&AssetID="..EmotesId

					local player = game.Players.LocalPlayer
					local character = player.Character
					local humanoid = character:WaitForChild("Humanoid")

					local animation = Instance.new("Animation")
					animation.AnimationId = Anim.AnimationId

					local animationTrack = humanoid:LoadAnimation(animation)
					animationTrack:Play()
				end
			end
		end
2 Likes

I put the link into an animation instance and it played fine. Also, you should use the animator instance under humanoid instead of the humanoid to load the animation. Try this?

					local animation = Instance.new("Animation")
					animation.AnimationId = "http://www.roblox.com/asset/?id=" .. tostring(Anim.AnimationId)

					local animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
					animationTrack:Play()
1 Like

It’s kind of funny, but I haven’t managed it yet. The error must be staring me in the face but I haven’t noticed it yet.

local HttpService = game:GetService("HttpService")
local StarterGui = game:GetService("StarterGui")
local InsertService = game:GetService('InsertService')
--
local ScreenGui = StarterGui.HUD
local EmoteFrame = ScreenGui:WaitForChild("EmoteFrame")
--
local URL = "https://catalog.roproxy.com/v1/search/items/details?Category=12&Subcategory=39&salesTypeFilter=1&Limit=30"
local response = HttpService:GetAsync(URL)
local decodedData = HttpService:JSONDecode(response)
--
if decodedData and type(decodedData) == "table" then
	if decodedData.data and type(decodedData.data) == "table" then
		local idsTable = {} 
		--
		for _, item in ipairs(decodedData.data) do
			if type(item) == "table" and item.id then
				table.insert(idsTable, item.id)
			end
		end
		--
		
		for i, EmotesId in pairs(idsTable) do
			local Emotes = tonumber(EmotesId)
			if Emotes then

				game.InsertService:LoadAsset(EmotesId).Parent = game.ReplicatedStorage.AnimEmotes
				local AnimEmotes = game.ReplicatedStorage.AnimEmotes:GetDescendants()

				for i, Anim in pairs(AnimEmotes) do
					local Template = script.Template:Clone()
					Template.Parent = EmoteFrame.EmotesContainer.Scrolling
					Template.Icon.Image = "http://www.roblox.com/Thumbs/Asset.ashx?Height=256&Width=256&AssetID="..EmotesId

					local player = game.Players.LocalPlayer

					if player and player.Character then
						local character = player.Character
						local humanoid = character:WaitForChild("Humanoid")

						local animation = Template.EmoteID
						animation.AnimationId = "http://www.roblox.com/asset/?id=" .. tostring(Anim:FindFirstChildOfClass("Model"):FindFirstChildOfClass("Animation").AnimationId)

						local animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
						animationTrack:Play()
					end
				end
			end
		end
	end
end
1 Like

Try to print some stuff (maybe like one in the loop to tell you the animation, another under the check for player and player.Character to tell you if it is still there). Also what is EmoteId?

idsTablee is a table that stores the Ids, so EmotesId loads the information according to the Id.

1 Like

My bad I meant Template.EmoteId lolll

1 Like

Sorry, I got it completely wrong

Captura de tela 2024-01-22 233426

this is a common mistake.

it’s best that you check this out

1 Like

something isn’t right…

PlayerGui
Captura de tela 2024-01-22 234738

ScreenGui
Captura de tela 2024-01-22 234749

Oh I was so focused on the animation part I missed that lol. You need to use player.PlayerGui instead of StarterGui.

1 Like

Captura de tela 2024-01-23 001700
:eyes:

You have to define the player variable. The player variable would just contain a reference to the player instance.

1 Like

I looked at some topics but couldn’t find anything that could help me.

local HttpService = game:GetService("HttpService")
local InsertService = game:GetService('InsertService')
--
local Player = game.Players.LocalPlayer
--
local MainFrame = Player.PlayerGui
local EmoteFrame = MainFrame.HUD.EmoteFrame
--
local URL = "https://catalog.roproxy.com/v1/search/items/details?Category=12&Subcategory=39&salesTypeFilter=1&Limit=30"
local response = HttpService:GetAsync(URL)
local decodedData = HttpService:JSONDecode(response)
--
if decodedData and type(decodedData) == "table" then
	if decodedData.data and type(decodedData.data) == "table" then
		local idsTable = {} 
		--
		for _, item in ipairs(decodedData.data) do
			if type(item) == "table" and item.id then
				table.insert(idsTable, item.id)
			end
		end
		--

		for i, EmotesId in pairs(idsTable) do
			local Emotes = tonumber(EmotesId)
			if Emotes then

				game.InsertService:LoadAsset(EmotesId):GetChildren()[1].Parent = game.ReplicatedStorage.AnimEmotes
				local AnimEmotes = game.ReplicatedStorage.AnimEmotes:GetChildren()

				for i, Anim in pairs(AnimEmotes) do
					local Template = script.Template:Clone()
					Template.Parent = EmoteFrame.EmotesContainer.Scrolling
					Template.Icon.Image = "http://www.roblox.com/Thumbs/Asset.ashx?Height=256&Width=256&AssetID="..EmotesId
					Template.EmoteID.AnimationId =  Anim.AnimationId	
				end
			end
		end
	end
end

You have to use “WaitForChild()” because the client loads first before any instance is loaded, hence “PlayerGui” cannot be found

1 Like

I tried this but got an error.

local Players = game:GetService("Players")

local MainFrame = Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("HUD")
local EmoteFrame = MainFrame:WaitForChild("EmoteFrame")

The error

ServerScriptService.Script:6: attempt to index nil with 'WaitForChild' 

Thank you for everyone’s help. Fortunately I reached my goal.