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

math.random relative to persons screen size?

Asked by
9phs 2
4 years ago
Edited 4 years ago

I would like the image to be placed randomly across the screen but keep it relative to the players window so even if they resized it it would fill from the left border to the right border, but by doing (0,1) it only places on either the right side or left side. So i was wondering if anyone had a solution for this

        local t = tick()
        for i = 1, 5 do
            local bubble = Instance.new("ImageLabel")
            bubble.Name = "bubble"
            bubble.Position = UDim2.new(math.random(0, 1), 0, 0, 0)
            bubble.Size = UDim2.new(0, 100, 0, 100)
            bubble.Parent = Player.PlayerGui.Loading.Frame
            bubble.Visible = true
        end

edit: this is the line im talking about

bubble.Position = UDim2.new(math.random(0, 1), 0, 0, 0)

0
I'm also wondering if there's a possibility i can use camera.viewportsize? but im not sure how to implement it 9phs 2 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I can't exactly do what your asking for but this might be a solution that you want

local t = tick()
for i = 1, 5 do
    local bubble = Instance.new("ImageLabel")
    bubble.Name = "bubble"
    bubble.Position = UDim2.new(math.random(1, 100) / 100, 0, 0, 0)--we get a random number 1 to 100 and divide it
    bubble.Size = UDim2.new(0, 100, 0, 100)
    bubble.Parent = Player.PlayerGui.Loading.Frame
    bubble.Visible = true
end
0
thank you so much i didn't even think about that 9phs 2 — 4y
Ad

Answer this question