as the title said: i want to make a troll game about asking my friend to play roblox, the gui show a title to ask if they want to play, if you hover on “no”, the “no” button automatically move to a random spot
but somehow it just move to my top left corner of the screen, even though the “warn” line work
i tried a lot of solution by using roblox studio built-in assistant, chatgpt, searching up all of the related thing but it wont help
heres the video and the path
and this is the script
local gui = script.Parent
local yes = gui.yes
local no = gui.no
local function hover()
no.Position = UDim2.new(math.random(0.1, 0.8), 0, math.random(0.1, 0.8), 0)
warn("bro tryna click no")
end
no.MouseEnter:Connect(hover)
Try changing the parameters of math.random(). The size a GUI object (to fit the whole screen) is {1, 0} {1, 0}, so you could change those parameters to 0, 1 for each math.random() statement.
So you would have: no.Position = UDim2.new(math.random(0, 1), 0, math.random(0, 1), 0)
or just: no.Position = UDim2.fromScale(math.random(0, 1), math.random(0, 1))
math.random goes to full intergers (in your case it will be always 0) so should maybe use Random.New():NextNumber()
local function hover()
local firstRndm = Random.new():NextNumber(.1, .8)
local secondRndm = Random.new():NextNumber(.1, .8)
no.Position = UDim2.new(firstRndm, 0, secondRndm , 0)
warn("bro tryna click no")
end
You can make your own decimal function, I don’t recommend this tbh because I am pretty sure there is an alternative but it worked so if you’re looking for fast solution:
local no = script.Parent
local function getRandomDecimal()
local xIndex, yIndex = math.random(1, 9), math.random(1, 9)
local X, Y
local Decimals = {.1, .2, .3, .4, .5, .6, .7, .8, .9}
local function loop(index)
for i, v in Decimals do
if i == index then
return v
end
end
end
X = loop(xIndex)
Y = loop(yIndex)
return X, Y
end
local function hover()
local X, Y = getRandomDecimal()
no.Position = UDim2.new(X, 0, Y, 0)
warn(no.Position)
warn("bro tryna click no")
end
no.MouseEnter:Connect(hover)
wowsers! thanks it worked, but i tested the others late reply and theyre worked too! but to be fair i will give the “solution” thing to the earliest reply, sorry for the others