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?
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
.