I don't really know much about viewportframes, however what I am trying to do is have an npc appear in a frame on the player's UI with movement. I did this using the technique shown on the devforums, however all I see is a static image that doesn't move. How would I constantly update the viewportframe to show the latest position of the npc?
Here is my code, does not portray movement:
local player = game.Players.LocalPlayer local vp = player:WaitForChild("PlayerGui"):WaitForChild("CountDown"):WaitForChild("Members").Frame.ViewportFrame local obj = workspace.TestSubject local camera = Instance.new("Camera") obj.Parent = vp camera.Parent = vp vp.CurrentCamera = camera local pos = obj.PrimaryPart.Position + obj.PrimaryPart.CFrame.LookVector*6 local lookAt = obj.PrimaryPart.Position camera.CFrame = CFrame.new(pos + Vector3.new(0,1,0), lookAt)
I am 100% sure this is not the most efficient way to do this, but I ended up cloning the model and constantly deleting and recloning it. I would probably also use the RunService for this. If anyone knows a better way please feel free to answer.
local player = game.Players.LocalPlayer local vp = player:WaitForChild("PlayerGui"):WaitForChild("CountDown"):WaitForChild("Members").Frame.ViewportFrame local obj = workspace.TestSubject local camera = Instance.new("Camera") local prevObj camera.Parent = workspace vp.CurrentCamera = camera while true do local newObj = obj:Clone() newObj.Parent = vp if prevObj then prevObj:Destroy() end prevObj = newObj local pos = obj.PrimaryPart.Position + obj.PrimaryPart.CFrame.LookVector*6 local lookAt = obj.PrimaryPart.Position camera.CFrame = CFrame.new(pos + Vector3.new(0,1,0), lookAt) wait() end