Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I get the 2d position of a part in a viewportframe?

Asked by 4 years ago

Okay so this question seems confusing but basically, I have a minimap script using viewportframes. heres the code

local viewport = script.Parent:WaitForChild("ViewportFrame")
local plr = game.Players.LocalPlayer
local world = workspace.World

world:Clone().Parent = viewport

local camera = Instance.new("Camera",workspace)
camera.CameraType = Enum.CameraType.Scriptable
camera.Name = "MiniCam"

local height = 100
viewport.CurrentCamera = camera
script.Parent.ImageLabel.Image = game.Players:GetUserThumbnailAsync(plr.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size100x100)

game:GetService("RunService").RenderStepped:Connect(function()
    local vec,onsc = workspace.Camera:WorldToScreenPoint(viewport.Character.Position)
    local pos = plr.Character.HumanoidRootPart.Position
    camera.CFrame = CFrame.new(Vector3.new(pos.X,height,pos.Z),pos)
    viewport.Character.CFrame = plr.Character.HumanoidRootPart.CFrame
end)

And my player shows up on the map but I want a gui to follow the 2d player on the 2d map. But I cant since viewportframes dont work like that. The part inside the viewportframe doesnt get converted to a gui. This is the video I watched. https://www.youtube.com/watch?v=nNOcjLDWKR8&t=85s . I actually want the players Icon to show on the map and not a part only, which is why im trying to get the 2d position of it. I hope you guys understand and a help would be appreciated.

Answer this question