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
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
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
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
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()
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
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?
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
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'