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

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

Asked by 4 years ago

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

Log in to vote
1
Answered by
VitroxVox 884 Moderation Voter
4 years ago

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)
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Answer this question