Im trying to make a equip system where this local script would get all equipped towers and place them into the GUI, but somehow the animation of the character doesn’t play?
local players = game:GetService('Players')
local localplayer = players.LocalPlayer
local folder = localplayer:WaitForChild('towersEquipped')
local function folderchildChanged()
-- TODO: um.. get the tower???
for _, v in pairs(folder:GetChildren()) do
local order = v:GetAttribute('order')
local place = script.Parent:FindFirstChild('Frame'..order)
local tower = v.Value
if place.viewport.WorldModel:FindFirstChild(tower.Name) and place.viewport.WorldModel:FindFirstChild('viewportCam') then
place.viewport.WorldModel:FindFirstChild(tower.Name):Destroy()
place.viewport.WorldModel:FindFirstChild('viewportCam'):Destroy()
end
local clonedtower = tower:Clone()
clonedtower.Parent = place.viewport.WorldModel
clonedtower.Name = tower.Name
local camera = Instance.new('Camera')
local root = clonedtower:WaitForChild('Head')
camera.Name = 'viewportCam'
camera.CameraType = 'Custom'
--camera.FieldOfView = '100'
local animation = clonedtower.AnimSaves:FindFirstChild('Idle')
local ani = clonedtower.Humanoid.Animator:LoadAnimation(animation)
ani:Play()
local cframeaddition = CFrame.fromEulerAnglesXYZ(0,math.rad(18),0) * CFrame.new(0.01,-0.3,1.2)
camera.CFrame = CFrame.new(root.Position + (root.CFrame.lookVector*1),root.Position) * cframeaddition
camera.Parent = place.viewport.WorldModel
place.viewport.CurrentCamera = camera
if ani.IsPlaying then
print('ok')
end
end
end
folderchildChanged()
folder.ChildRemoved:Connect(folderchildChanged)
folder.ChildAdded:Connect(folderchildChanged)