Hello, so, I cannot play animations within ViewportFrames, I have seen many of these before but no solutions work, or maybe I am doing it wrong.
However, I need help for a shop system, here is the current script:
for i, v in pairs(game.ReplicatedStorage.Emotes:GetChildren()) do
local frame
if v:FindFirstChild("CoinPrice") then
frame = script.CoinTemplate:Clone()
frame.Price.Text = v.CoinPrice.Value
elseif v:FindFirstChild("GemsPrice") then
frame = script.GemsTemplate:Clone()
frame.Price.Text = v.GemsPrice.Value
else
return
end
frame.ViewportFrame.EmoteGuy.Humanoid.Animator:LoadAnimation(frame.ViewportFrame.EmoteGuy:FindFirstChild(v.Name)):Play()
frame.Name = v.Name
frame.Parent = script.Parent
frame.MouseButton1Click:Connect(function()
script.Parent.Parent.PurchaseConfirm.Visible = true
script.Parent.Parent.PurchaseConfirm.ViewportFrame.EmoteGuy.Humanoid.Animator:LoadAnimation(script.Parent.Parent.PurchaseConfirm.ViewportFrame.EmoteGuy:FindFirstChild(v.Name)):Play()
script.Parent.Parent.PurchaseConfirm.TextLabel.Text = frame.Name
end)
end
I think you need to parent your character before calling Animator:LoadAnimation on it.
for i, v in pairs(game.ReplicatedStorage.Emotes:GetChildren()) do
local frame
if v:FindFirstChild("CoinPrice") then
frame = script.CoinTemplate:Clone()
frame.Price.Text = v.CoinPrice.Value
elseif v:FindFirstChild("GemsPrice") then
frame = script.GemsTemplate:Clone()
frame.Price.Text = v.GemsPrice.Value
else
return
end
frame.Name = v.Name
frame.Parent = script.Parent
frame.ViewportFrame.EmoteGuy.Humanoid.Animator:LoadAnimation(frame.ViewportFrame.EmoteGuy:FindFirstChild(v.Name)):Play()
frame.MouseButton1Click:Connect(function()
script.Parent.Parent.PurchaseConfirm.Visible = true
script.Parent.Parent.PurchaseConfirm.ViewportFrame.EmoteGuy.Humanoid.Animator:LoadAnimation(script.Parent.Parent.PurchaseConfirm.ViewportFrame.EmoteGuy:FindFirstChild(v.Name)):Play()
script.Parent.Parent.PurchaseConfirm.TextLabel.Text = frame.Name
end)
end
Nope, that didnt work, even changing the script entirely:
here is what it is now
for i, v in pairs(game.ReplicatedStorage.Emotes:GetChildren()) do
local frame
if v:FindFirstChild("CoinPrice") then
frame = script.CoinTemplate:Clone()
frame.Price.Text = v.CoinPrice.Value
elseif v:FindFirstChild("GemsPrice") then
frame = script.GemsTemplate:Clone()
frame.Price.Text = v.GemsPrice.Value
else
end
frame.Name = v.Name
frame.Parent = script.Parent
local cloned = v:Clone()
cloned.Parent = frame.ViewportFrame
for i, x in pairs(cloned:GetChildren()) do
if x:IsA("Animation") then
v.Humanoid.Animator:LoadAnimation(x):Play()
end
end
frame.MouseButton1Click:Connect(function()
script.Parent.Parent.PurchaseConfirm.Visible = true
script.Parent.Parent.PurchaseConfirm.TextLabel.Text = frame.Name
end)
end