Hey! I’m trying to load a NPC into a viewport frame, and then make it pose. I went about this by making an idle animation, and it doesn’t seem to be playing. I’m pretty bad with anything animation so it might be something little I overlooked. Here is my code:
local repStorage = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
for i, frame in pairs(script.Parent:GetChildren()) do
if frame:IsA("Frame") and frame.Tower.Value ~= "None" then
local model = repStorage.Towers[frame.Tower.Value]:Clone()
model:PivotTo(CFrame.new(0, 0, 0))
model.Parent = frame.ViewportFrame
local animation = model.Humanoid:LoadAnimation(model.ViewportAnimation)
animation:Play()
local viewportCamera = Instance.new("Camera", frame.ViewportFrame)
frame.ViewportFrame.CurrentCamera = viewportCamera
viewportCamera.CFrame = CFrame.new(Vector3.new(0, 3, 4))
end
end
-- Revamped Code
local repStorage = game:GetService("ReplicatedStorage")
local towers = repStorage:WaitForChild('Towers', 10)
local player = game:GetService("Players").LocalPlayer
local parent = script.Parent
for _, frame in ipairs(parent:GetDescendants()) do
if frame:IsA('Frame') then
local frameTower = frame:WaitForChild('Tower', 10) :: StringValue
local viewportFrame = frame:WaitForChild('ViewportFrame', 10) :: ViewportFrame
if frameTower and viewportFrame and frameTower.Value ~= "None" then
local model = towers:WaitForChild(frameTower.Value, 10):Clone()
model:PivotTo(CFrame.new(0, 0, 0))
model.Parent = viewportFrame
local viewPortAnimation = model:WaitForChild('ViewportAnimation', 10)
local animation = model.Humanoid:LoadAnimation(viewPortAnimation, 10)
animation:Play()
local viewportCamera = Instance.new("Camera", viewportFrame)
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.CFrame = CFrame.new(0, 3, 4) -- I changed Vector3.new(0,3,4) to this because they do the same thing
end
end
end
And second, could you show me how your files are placed?
I’m not sure what you mean by my “files,” but if you mean the explorer then I can show you. I also forgot to mention also that it gives no errors in the output. All children of TowersFrame have the same children under them. (Besides script)
try placing a worldmodel into the viewportframe and then cloning the npc into the worldmodel, from what i read worldmodels have the ability to play animations within viewports.