Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I fix and make the TextButton to move to a random position?

Hello, I made a instance.new TextButton and I want it to go to a random place in the screen gui this is the script that I made

local xPos = math.random(0.021, 0.953)
local yPos = math.random(0.146,0.917)

local Point = Instance.new("TextButton", game.StarterGui.ScreenGui)
Point.Visible = true
Point.Position = Vector3.new(xPos, yPos)

When I run this nothing happens and the error is

PlayerGui.ScreenGui.LocalScript:7: bad argument #3 (UDim2 expected, got Vector3)

Could I get help fixing this script?

2 answers

✓ Accepted answer

You just messed up on vector3.new because a UI isn't a Part so it uses UDM2 fix for this is:

local xPos = math.random(0.021, 0.953)
local yPos = math.random(0.146,0.917)

local Point = Instance.new("TextButton", game.StarterGui.ScreenGui)
Point.Visible = true
Point.Position = UDim2.new(xPos, yPos)

game.StarterGui.ScreenGui refers to the starter gui, not the current player's gui. To add something to that, you'd have to do game.Players.someusername.PlayerGui.ScreenGui, or if this is a LocalScript, simply game.Players.LocalPlayer.PlayerGui.ScreenGui.

This discussion is preserved as it was. New answers, comments, and votes are closed.