How to make a gui size set to scale with a script

I have a simple script that inserts an image but the problem is that the image size doesn’t scale so if you play on a phone the images are going to be all messed up. here’s a photo of what I mean.

how it’s supposed to look (on pc)
image

how it looks on a phone…
image

here’s the script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ImageEvent = ReplicatedStorage.ShopEvents:WaitForChild("ImageEvent")

local function NewImageLable(ImageId)
	local label = Instance.new("ImageLabel")
	local ImageId = ImageId
	label.Parent = script.Parent
	label.BackgroundTransparency = 1
	label.Image = "rbxassetid://".. ImageId
	-- set the unit conversion of the position and size of the gui here
end

ImageEvent.OnClientEvent:Connect(function(ImageId)
	NewImageLable(ImageId)
end)

just use scale instead offset (char limit)
image

or

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ImageEvent = ReplicatedStorage.ShopEvents:WaitForChild("ImageEvent")

local function NewImageLable(ImageId)
	local label = Instance.new("ImageLabel")
	local ImageId = ImageId
	label.Parent = script.Parent
	label.BackgroundTransparency = 1
	label.Image = "rbxassetid://".. ImageId
	if game.UserInputService.TouchEnabled then
        local OptimizationScale = Instance.new("UIScale")
        OptimizationScale.Name = "OptimizationScale"
        OptimizationScale.Parent = label
        OptimizationScale.Scale = .5
     end
end

ImageEvent.OnClientEvent:Connect(function(ImageId)
	NewImageLable(ImageId)
end)

hmmm, so I was looking at my code and I don’t think it’s the problem it’s the UIGridLayout that’s making it not scale correctly. It was set to offset but I changed it to scale. But still thank you for looking at my post :slight_smile:

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