Animations inside Viewport GUI not working, even with a WorldModel

I’m trying to make a loot crate oppening animation inside a GUI using a viewport.

This is whats inside the viewport:
image

And this is whats inside the Animator script:

local animation = script:WaitForChild("Animation")
local humanoid = script.Parent:WaitForChild("Humanoid")
local anim = humanoid:LoadAnimation(animation)

script.Parent.PlayAnim.Event:Connect(function()
	print("playing crate animation")
	anim:Play()
	anim.TimePosition = 0
	anim:AdjustSpeed(1)
end)

The animation just wont play for some odd reason, the script gets the event and starts the animation, the viewport doesn’t update it i guess.

This is the crate animation:

…And the animation inside the viewport:

(i used tween service to tween the crate going up and down btw)

Heres the Main Controler script:

local TS = game:GetService("TweenService")
local info = TweenInfo.new(2,Enum.EasingStyle.Back,Enum.EasingDirection.Out)
local info2 = TweenInfo.new(2,Enum.EasingStyle.Back,Enum.EasingDirection.In)

local function tweenModel(model, CF,tweeninfo)
	local CFrameValue = Instance.new("CFrameValue")
	CFrameValue.Value = model:GetPrimaryPartCFrame()

	CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
		model:SetPrimaryPartCFrame(CFrameValue.Value)
	end)

	local tween = TS:Create(CFrameValue, tweeninfo, {Value = CF})
	tween:Play()

	tween.Completed:Connect(function()
		CFrameValue:Destroy()
	end)
end

local function createViewport()
	local viewportFrame = Instance.new("ViewportFrame")
	viewportFrame.Size = UDim2.new(1,0,1,0)
	viewportFrame.Position = UDim2.new(0,0,0,0)
	viewportFrame.BackgroundColor3 = Color3.new(0, 0, 0)
	viewportFrame.BorderColor3 = Color3.new(0,0,0)
	viewportFrame.BorderSizePixel = 0
	viewportFrame.BackgroundTransparency = 1
	viewportFrame.Parent = script.Parent.CrateGui
	viewportFrame.ZIndex = 50
	viewportFrame.Name = "CrateViewport"

	local box = game.ReplicatedStorage.ViewPorts.Box:clone()
	box.Parent = viewportFrame

	local fakeCam = game.ReplicatedStorage.ViewPorts.Cam:clone()
	fakeCam.Parent = viewportFrame

	local worldModel = Instance.new("WorldModel")
	worldModel.Parent = viewportFrame
	worldModel.PrimaryPart = box.PrimaryPart

	local viewportCamera = Instance.new("Camera")
	viewportFrame.CurrentCamera = viewportCamera
	viewportCamera.Parent = viewportFrame
	--viewportCamera.CFrame = box:GetModelCFrame() * CFrame.new(0,1,5)
	viewportCamera.CFrame = fakeCam.CFrame
	worldModel.PrimaryPart.Parent:SetPrimaryPartCFrame(worldModel.PrimaryPart.Parent:GetPrimaryPartCFrame()-Vector3.new(0,7,0))
	return box, worldModel
end

script.Parent.Crate.Event:Connect(function(plr,playerClasses)
	local box, worldModel = createViewport()
	print(box.Parent)
	tweenModel(worldModel.PrimaryPart.Parent, worldModel.PrimaryPart.Parent:GetPrimaryPartCFrame()+Vector3.new(0,7,0),info)
	wait(1.6)
	worldModel.PrimaryPart.Parent.PlayAnim:Fire()
	wait(15)
	tweenModel(worldModel.PrimaryPart.Parent, worldModel.PrimaryPart.Parent:GetPrimaryPartCFrame()-Vector3.new(0,7,0),info2)
end)

I’ve tried basicly everything i knew and i searched on the dev forum for help, i found that i needed to use WorldModels, but no luck. I tested to see if it was an animation problem but it was working perfectly fine.

try parenting the box to the WorldModel.

also you should probably use Animation Controller when animating object and try playing the animation using local script instead of a script

thanks, but sadly it didn’t help me a bunch, i made the script a localscript, i used an AnimationControler instead of the humanoid, i tried messing arround with the WorldModel, i even took the script out of the model and put inside the GUI where the Main controler script as at and used a RemoteEvent to fire it with the box, parents and stuff but nothing

You’re doing this on Local Script or regular Script?
Animations should (or even have to) be loaded in and played from Local Script.

I tried both but nothing, i even moved the scripts outside the model to see if it worked but no

I would recommend using :WaitForChild() to make animations load in.
Most propably - script tries to load in animation before object existence begin.
Also - try using TweenService
It better option than quick-tweening which is partically deprecated
Try putting this as first line in animation handling script.

local object = viewportFrame:WaitForChild(-- what object/part you're looking for)

still nothing, i’ll try a couple more things and wait a little more to see if more people answer
if nothing works then ima just use tween service and hinges to animate the crate
thanks for the help

That’s what Im saying.
It’s less glitchy and safer to use TweenService.
Also - could You provide me a footage or video of what happening, and explain what do You want to achieve?

I’m trying to put this animations

…inside the viewport crate

but it just doesnt play

1 Like

I have no idea what is going on then.

where you record the videos? is gyazo?

no, i was using the default roblox studio recorded, but i usualy record stuff with OBS Studio

i changed it, now with tween service its working