Need help with random position of UI

I have made a little money UI, that pops up randomly on the screen. But the thing is, it pops up, but not at a random position.

I have a code here for this

local Tbcl = game.Workspace.Tutorial.TutorialButton.ClickDetector
local Tbclc1 = game.Workspace.Tutorial.TutorialButtonClone1.ClickDetector
local Tbclc2 = game.Workspace.Tutorial.TutorialButtonClone2.ClickDetector
local localplayergui = game.Players.LocalPlayer.PlayerGui
local Moneymainstorage = game.ReplicatedStorage.MoneyMain


Tbcl.MouseClick:Connect(function()
	local MoneyMain = Moneymainstorage:Clone()
	MoneyMain.Parent = localplayergui
	MoneyMain.Sound:Play()
	
	local XPos = math.random(0.1, 0.9)
	local YPos = math.random(0.1, 0.9)
	MoneyMain.MoneySign.Position = UDim2.new(XPos, 0, YPos, 0)
	
	for a = 1,50,1 do
		MoneyMain.MoneySign.TextTransparency = MoneyMain.MoneySign.TextTransparency - 0.02
		wait()
	end
	wait(2)
	for b = 1,50,1 do
		MoneyMain.MoneySign.TextTransparency = MoneyMain.MoneySign.TextTransparency + 0.02
		wait()
	end
	print("+3")
	MoneyMain:Destroy()
end)

But it always ends up in the same corner.

Samecorner

math.random always return rounded, use :NextNumber instead

local XPos = Random.new():NextNumber()
local YPos = Random.new():NextNumber()

or maybe just

local XPos = math.random(100, 900) / 1000
local YPos = math.random(100, 900) / 1000
3 Likes

Alright, thanks allot on helping me. It instantly worked.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.