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

How to convert [UDim2 to Vector2]? (NOT [Vector2 to UDim2]!!

Asked by 5 years ago

Okay so, i know its possible to make it from (Vector3 & Vector3) to UDim2, but i dont know how to make it turned around. Like for example, i want to have Vector2 of a Button in the players screen.

Okay so:

  • Player is at a BillboardGUI with buttons.
  • Player needs the Vector2 of it, when the Button.Position is UDim2

What would you need to do to convert that UDim2 to a Vector2?

0
I honestly don't think you can. The way UDim2 works is completely different from Vector2. UDim2 is mainly used for GUI tweening while Vector2 is mainly just a position placeholder for a GUI. DeceptiveCaster 3761 — 5y
0
UDim2's are made up of 2 UDim values, the X and Y axes, so it's going to be difficult because there are four numbers and Vector2 is just 2 numbers........................ User#24403 69 — 5y
0
But.. i need to get the ScreenPosition (Vector2) of a button on someones screen. CrazyScript3r 67 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Okay, so if I am understanding you correctly, you simply want to convert the datatype Vector2 to a UDim2? I wasn't sure what you meant, so I prepared three replies.

Casting GUI object to 3D space I thought you might have meant this. I searched maybe twenty minuets, but I wasn't able to see anything. Unfortunately, I don't see any easy way to cast a GUI object on a player's screen to a position in the 3D environment.

Simply Converting Types I'm not sure why you would need to do this, but I thought there was a possibly that you might need to cast the one type to the other, maybe because you need a method only available in UDim2? Anyways, that's simple. You would just do something like this, with A and B being Vector2s you pass as arguments, and C being the UDim2 output.

local C = UDim2.new(A.X, A.Y, B.X, B.Y)

I do, however, assume this isn't what you need, since that doesn't seem to pose any usages, and I don't see any real reason for it.

Having the player click a button on a Billboard GUI This one is actually quite easy. In fact, in really only requires a few extra steps. Instead of putting it on the block itself, have a code put it in each new player's PlayerGui. Just make sure to set the adorne value to what block is should be shown on. Now, you can use the GUI similar to a ScreenGUI. Like magic!

In case you're a little confused, I created an example world, with a very simple Billboard GUI, with a single button on it. When you join, you're able to click that button. I uploaded it to my GitLabs server here

I hope I was able to solve your question, if so, please mark my answer as accepted, if not, please respond to me, so I can see if I can help you out.

Ad

Answer this question