How to convert Vector3 to Udim2

Hello!
I got idea for my shooting game when player do headshot then on the head of that player that have headshot for the shooter will show this “Headshot” text and slowly upping and transparenting to 1
But I need know how to make from vector3 to Udim2 position so I can see position of label
Thank for any help!

1 Like

You use the camera:WorldToScreenScreenPoint(Vector3 pos).

An example:

local camera = workspace.CurrentCamera
local worldPoint = target.Head.Position

local vector, onScreen = camera:WorldToScreenPoint(worldPoint)

local screenPoint = Vector2.new(vector.X, vector.Y)

target would need to be specified.

1 Like

Yes. You would need a localscript.

1 Like

Sorry I got idea how to do it I will just fire client function that will show it

1 Like

Well I did this script it creates the label but don’t show it and position is set right

--local script
game.ReplicatedStorage.Headshot.OnClientEvent:Connect(function(text,pos)
	local camera = workspace.CurrentCamera
    local worldPoint = pos
    local vector, onScreen = camera:WorldToScreenPoint(worldPoint)
 
    local screenPoint = Vector2.new(vector.X, vector.Y)
	local Text = Instance.new("TextLabel",script.Parent.Texts)
	Text.BackgroundTransparency = 1
	Text.Position = UDim2.new(vector.X,vector.Y)
	Text.BorderSizePixel = 0
	Text.Text = text
	Text.TextScaled = true
	local Tween = game:GetService("TweenService"):Create(Text,TweenInfo.new(3,Enum.EasingStyle.Sine,Enum.EasingDirection.In),{Position = UDim2.new(vector.X,vector.Y + 0.9),TextTransparency = 1})
	Tween:Play()
	wait(3)
	Text:Destroy()
end)
1 Like

Can you give me some info please, I can’t even see the output or images. A video of you making the headshot with the output open and the folder where the text should appear in open in the explorer would be ideal.

1 Like

I don’t getting any output (30 chars)

Can you still send me a video of this please, I can’t help to fix it by only seeing the code.

Try replacing the Text’s position with the screenpoint.

Camera:WorldToScreenPoint gives the position In pixels… What you should do is

Text.Position = Udim2.new(0, vector.X, 0, vector.Y)
1 Like

Because of risk my game I will try it on new place