How to make an object go to a gui?

@Pooglies, check this new Code out!
Edit: @Pooglies, check out the code Number2!

Code1
--local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera.ViewportSize
local RE = game.ReplicatedStorage:WaitForChild("Send")
 
RE.OnClientEvent:Connect(function(player)
print("received")
[[--  local Random = Random.new()
function GetRandomPosition(V)
   return UDim.fromOffset(Random:NextNumber(V.X, camera.X), Random:NextNumber(V.Y, camera.Y))
end--]]
 local camera = workspace.CurrentCamera
 local worldPoint = workspace.Part.Position
 local Vector, IsOnScreen = camera:WorldToScreenPoint(worldPoint)
 local ScreenGui = Instance.new("ScreenGui", player.PlayerGui)
 local Gui = Instance.new("Frame", ScreenGui)

local RandomX = math.random(0, camera.ViewportSize.X - Gui.AbsoluteSize.X)
local RandomY = math.random(0, camera.ViewportSize.Y - Gui.AbsoluteSize.Y) 

if IsOnScreen and RandomX < (Vector.X + 15) and RandomY < (Vector.Y + 15) then
   Vector.X = RandomX
   Vector.Y = RandomY
end

 --locel Depth = Vector.Z
 local screenPoint = UDim2.fromOffset(Vector.X, Vector.Y)
 local Image = Instance.new("ImageLabel", Gui)
--local vectorp = screenPoint.Position
Gui.Size = UDim2.new(0.086, 1, 0.061, 1)
Image.Size = UDim2.fromScale(1,1)
Image.Image = "http://www.roblox.com/asset/?id=8057767"
Gui.AnchorPoint = Vector2.new(0.5, 0.5)
Gui.Position = screenPoint
Image.AnchorPoint = Vector2.new(0.5, 0.5)
Image.Position = UDim2.fromScale(0.5, 0.5)
wait(1)
Gui:TweenSizeAndPosition(UDim2.fromScale(0.086, 0.061) ,UDim2.fromScale(0.15, 0.15), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 4) --It will tween the Gui to the 0.15, 0.15 Scale position.
end)
Code2
--ServerScript
local CollectionService = game:GetService("CollectionService")
for i,v in pairs(workspace:GetChildren())do
    if v.Name == "Currency" then
        CollectionService:AddTag(v, "Currency")
    end
end
--LocalScript
local RE = Istance.new("Remote Event", game.ReplicatedStorage)
RE.Name = "RE"
local player = game.Players.LocalPlayer
while wait(0.01) do
    local CollectRadius = 10
    local HRP = player.Character.HumanoidRootPart
    local CollectionService = game:GetService("CollectionService")
    local Currency = CollectionService:GetTagged("Currency")
 HRP:GetPropertyChangedSignal("Position"):Connect(function()
     if (HRP.Position - Currency.Position).magnitude =< CollecRadius then
        RE:FireServer(player)
     end
  end)
end

--ServerScript
--local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera.ViewportSize
local RE = game.ReplicatedStorage:WaitForChild("Send")
 
RE.OnClientEvent:Connect(function(player)
print("received")
[[--  local Random = Random.new()
function GetRandomPosition(V)
   return UDim.fromOffset(Random:NextNumber(V.X, camera.X), Random:NextNumber(V.Y, camera.Y))
end--]]
 local camera = workspace.CurrentCamera
 local worldPoint = workspace.Part.Position
 local Vector, IsOnScreen = camera:WorldToScreenPoint(worldPoint)
 local ScreenGui = Instance.new("ScreenGui", player.PlayerGui)
 local Gui = Instance.new("Frame", ScreenGui)

local RandomX = math.random(0, camera.ViewportSize.X - Gui.AbsoluteSize.X)
local RandomY = math.random(0, camera.ViewportSize.Y - Gui.AbsoluteSize.Y) 

if IsOnScreen and RandomX < (Vector.X + 15) and RandomY < (Vector.Y + 15) then
   Vector.X = RandomX
   Vector.Y = RandomY
end

 --locel Depth = Vector.Z
 local screenPoint = UDim2.fromOffset(Vector.X, Vector.Y)
 local Image = Instance.new("ImageLabel", Gui)
--local vectorp = screenPoint.Position
Gui.Size = UDim2.new(0.086, 1, 0.061, 1)
Image.Size = UDim2.fromScale(1,1)
Image.Image = "http://www.roblox.com/asset/?id=8057767"
Gui.AnchorPoint = Vector2.new(0.5, 0.5)
Gui.Position = screenPoint
Image.AnchorPoint = Vector2.new(0.5, 0.5)
Image.Position = UDim2.fromScale(0.5, 0.5)
wait(1)
Gui:TweenSizeAndPosition(UDim2.fromScale(0.086, 0.061) ,UDim2.fromScale(0.15, 0.15), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 4) --It will tween the Gui to the 0.15, 0.15 Scale position.
end)
4 Likes