I’m trying to make a loot crate oppening animation inside a GUI using a viewport.
This is whats inside the viewport:
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.