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:
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
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