#gui scaling for mobile devices doesnt work

1 messages · Page 1 of 1 (latest)

sturdy tapir
#

any ideas on how to fix this? image and video of what it's tryna change is shown.

code:

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local gui = playerGui:WaitForChild("mainGui")
local frame = gui:WaitForChild("MainFrame")

frame.AnchorPoint = Vector2.new(0.5, 0.5)
frame.Position = UDim2.new(0.5, 0, 0.5, 0)

local function scaleUI()
    local screenX, screenY = playerGui.AbsoluteSize.X, playerGui.AbsoluteSize.Y

    if UserInputService.TouchEnabled then
        -- MOBILE
        local widthScale = math.clamp(screenX / 1080, 0.5, 0.9)
        local heightScale = math.clamp(screenY / 1920, 0.5, 0.8)
        frame.Size = UDim2.new(widthScale, 0, heightScale, 0)
    else
        -- DESKTOP/PC
        local widthScale = math.clamp(screenX / 1920, 0.5, 0.6)
        local heightScale = math.clamp(screenY / 1080, 0.5, 0.5)
        frame.Size = UDim2.new(widthScale, 0, heightScale, 0)
    end
end

if playerGui.AbsoluteSize.X == 0 then
    RunService.RenderStepped:Wait()
end

scaleUI()
playerGui:GetPropertyChangedSignal("AbsoluteSize"):Connect(scaleUI)
UserInputService.TouchEnabledChanged:Connect(scaleUI)
dense siren
#

and not coding the property...

sturdy tapir
#

wait

#

am i dumb

dense siren
#

probably

#

there was plugin

#

autoscale lite

#

it turns size in pixels to scale

#

so it looks same

#

but its now scale so it scales with device size

balmy adder
# sturdy tapir

if you dont want to use a plugin you can look at the size then see your using offset so for example {0,505,0,606} {Scale X,Offset X, Scale Y ,Offset Y}

rough dagger
#

I would highly recommend using a plugin, it makes ur life with uis 10 times easier