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.
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:
1 | local frame = script.Parent.Parent.Frame |
2 | while wait(. 1 ) do -- change the wait delay higher to make it go slower! |
3 | frame.Position = UDim 2. new(math.random(),math.random(), math.random()) |
4 | 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
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 :
1 | while wait(. 1 ) do |
2 | script.Parent.Position = UDim 2. new(math.random(),math.random(),math.random(),math.random()) |
3 | end |
Hope this helped! :D