How to make an object go to a gui?

So I was scrolling on twitters creations and stumbled upon this amazing currency system where the tickets on the ground when touched, go to a gui and up to the players money count, I was wondering how to do something like this? https://twitter.com/i/status/1093594696516071424

10 Likes

You can pretty easily use the WorldToScreenPoint or WorldToViewportPoint function of the camera to do this

3 Likes

I have never heard of this, can you elaborate or show me some examples?

1 Like

local camera = workspace.CurrentCamera
local worldPoint = Vector3.new(0, 10, 0)
local Vector = camera:WorldToScreenPoint(worldPoint)
local screenPoint = Vector2.new(Vector.X, Vector.Y)

1 Like

How do I get the part on the ground? I don’t work in vector usually.

I think they have a conveyor in there, and they set the anchored to false for the part

Replace the worldPoint variable with the parts position, I just gave an example of how to use WorldToScreenPoint not a solution

3 Likes

I’ve never heard of this function either, but I’ll try to script you a script with @spawnify explanations:

[[local Script]]
local RE = istance.new("Remote Event", game.ReplicatedStorage)
RE.Name = "RE"
local player = game.Players.LocalPlayer
while wait(0.01) do
    local Children = player:GetChildren()
    Children.Touched:Connect(function(hit)
        RE.FireServer(player, hit)
    end)
end
[[local Script]]
local RE = game.ReplicatedStorage:WaitForChild("RE")
RE.OnServerEvent:Connect(fucntion(player)
     local camera = workspace.CurrentCamera
     local worldPoint = workspace.Currency
     local Vector = camera:WorldToScreenPoint(worldPoint)
     local screenPoint = UDim2.new(Vector.X, 0, Vector.Y, 0)
     local ScreenGui = istance.new("ScreenGui", player.PlayerGui)
     local Gui = istance.new("Frame", ScreenGui)
     Gui.AnchorPoint = Vector2.new(0.5, 0.5)
     Gui.Position = screenPoint
end)

EDIT: Wait a bit, it is WIP (Work In Progess)
EDIT2: Its ready to test (i write this on a IPad, i cant test it).

2 Likes

Okay thank you so much. I will definetly see what i can do with this.

1 Like

Okay so I do understand that you did this on an Ipad, but I do have some issues to explain, so in the script

local player = game.Players.LocalPlayer

local RE = game.ReplicatedStorage:WaitForChild("Send")
RE.OnClientEvent:Connect(function()
	print("received")
     local camera = workspace.CurrentCamera
     local worldPoint = workspace.Part.Position
     local Vector = camera:WorldToScreenPoint(worldPoint)
     local screenPoint = Vector2.new(Vector.X, Vector.Y)
     local ScreenGui = Instance.new("ScreenGui", player.PlayerGui)
     local Gui = Instance.new("Frame", ScreenGui)
     local Image = Instance.new("ImageLabel", Gui)
Image.Image = "8057767"
     Gui.AnchorPoint = Vector2.new(0.5, 0.5)
     Gui.Position = screenPoint --- It gives me an error saying "UDim2 expected, got Vector2"
end)

also, for the worldPoint, it was saying it couldn’t get the worldtoscreenpoint because the worldpoint wasn’t “known” or something, and so I put position. (I have no idea if this is correct or not) and am just curious what I can do.

4 Likes

Okay so I have been working now a little, and got it to work a little bit, but the positioning does not change for the “Gui” which makes me believe im doing something wrong with the part.

local player = game.Players.LocalPlayer

local RE = game.ReplicatedStorage:WaitForChild("Send")
RE.OnClientEvent:Connect(function()
	print("received")
     local camera = workspace.CurrentCamera
     local worldPoint = workspace.Part.Position
     local Vector = camera:WorldToScreenPoint(worldPoint)
     local screenPoint = Vector2.new(Vector.X, Vector.Y)
     local ScreenGui = Instance.new("ScreenGui", player.PlayerGui)
     local Gui = Instance.new("Frame", ScreenGui)
     local Image = Instance.new("ImageLabel", Gui)
local vectorp = screenPoint.Position
Gui.Size = UDim2.new(0.086, 1, 0.061, 1)
Image.Size = UDim2.new(1, 1, 1, 1)
Image.Image = "http://www.roblox.com/asset/?id=8057767"
     Gui.AnchorPoint = Vector2.new(0.5, 0.5)
     Gui.Position = UDim2.new(vectorp)
     Image.Position = UDim2.new(1,1, 1,1)
end)
4 Likes

Sorry, i edit the script, try it.

I have try to modify your script, look it out:

local player = game.Players.LocalPlayer

local RE = game.ReplicatedStorage:WaitForChild("Send")
RE.OnClientEvent:Connect(function()
print("received")
 local camera = workspace.CurrentCamera
 local worldPoint = workspace.Part.Position
 local Vector = camera:WorldToScreenPoint(worldPoint)
 local screenPoint = UDim2.fromScale(Vector.X, Vector.Y, )
 local ScreenGui = Instance.new("ScreenGui", player.PlayerGui)
 local Gui = Instance.new("Frame", ScreenGui)
 local Image = Instance.new("ImageLabel", Gui)
--local vectorp = screenPoint.Position
Gui.Size = UDim2.new(0.086, 1, 0.061, 1)
Image.Size = UDim2.new(1, 1, 1, 1)
Image.Image = "http://www.roblox.com/asset/?id=8057767"
Gui.AnchorPoint = Vector2.new(0.5, 0.5)
Gui.Position = screenPoint
Image.Position = UDim2.new(1,1, 1,1)
end)

Say me if it work.

The script I have currently, works, but it does not reposition the “Gui” and I do not get any errors saying why?

1 Like

I think that you should remplace (Sorry for the bad english) the Vector2.new() with the UDim2.new()
Sheck (i am realy bad in english, sorry!) out the code above.
Edit: i Reedited it and made it for you. See the code above (my reply)

Your english is okay my man, but besides that, its still not repositioning the image, heres a screenshot

3 Likes


i have it, its Offset! Try this code:

local player = game.Players.LocalPlayer

local RE = game.ReplicatedStorage:WaitForChild("Send")
RE.OnClientEvent:Connect(function()
print("received")
 local camera = workspace.CurrentCamera
 local worldPoint = workspace.Part.Position
 local Vector = camera:WorldToScreenPoint(worldPoint)
 --locel Depth = Vector.Z
 local screenPoint = UDim2.fromOffset(Vector.X, Vector.Y, )
 local ScreenGui = Instance.new("ScreenGui", player.PlayerGui)
 local Gui = Instance.new("Frame", ScreenGui)
 local Image = Instance.new("ImageLabel", Gui)
--local vectorp = screenPoint.Position
Gui.Size = UDim2.new(0.086, 1, 0.061, 1)
Image.Size = UDim2.new(1, 1, 1, 1)
Image.Image = "http://www.roblox.com/asset/?id=8057767"
Gui.AnchorPoint = Vector2.new(0.5, 0.5)
Gui.Position = screenPoint
Image.Position = UDim2.new(1,1, 1,1)
end)
3 Likes

yes! this works, but how would I make it so the image is the size of the part (depending on distance)

2 Likes
Image.Size = UDim2.fromOffset(workspace.Currency.Size.X, workspace.Currency.Size.Y)

Try this

Doesn’t seem to work. No errors either.