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

How do I position a Gui with a script? I can't figure it out on my own.

Asked by 6 years ago

Im new to scripting but I would like to know how you can position a ScreenGui with a script. It would be awesome if you could even tell me how I could randomly position it in a loop.

2 answers

Log in to vote
0
Answered by 6 years ago

put this code in a regular script. Put the script a parent of the frame (Put the script inside the frame). Then we will use the math math.random() to pick a random number for us.

so like:

local frame = script.Parent.Parent.Frame
while wait(.1) do -- change the wait delay higher to make it go slower!
    frame.Position = UDim2.new(math.random(),math.random(), math.random())
end

if you want it to go random position but in certain areas you can just add values in the math.random()

for example:

math.Random(100) The (100) picks any random number below 100.


If this works please accept this answer! Thank you!

-Mohawkid14

0
when i enter a value noting will show up, so when i don't put anything in it will show it moving randomly but in the corner only. lolkid007 43 — 6y
0
I know this post is already old, but I highly recommend you use localscripts instead of regular (server) scripts. If you're using FilteringEnabled, the GUI will NOT work with server scripts! Even if you don't use it, I still recommend using localscripts. User#20279 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

You use something called UDim2 to set the position of a GUI. Also you can't set a ScreenGui position, that's just something that holds the GUI. :P

If you want it to be in a loop and do random positions, you can use a while true do loop and math.random to do it.

It'd be something like this :

while wait(.1) do
    script.Parent.Position = UDim2.new(math.random(),math.random(),math.random(),math.random())
end

Hope this helped! :D

Answer this question