"Offset cannot be assigned to" error

I’m trying to make scaled UI for mobile so that it fits on screen and it won’t let me change the offset. It gives me an error: “Offset cannot be set to”

Here’s the script:

local UserInputService = game:GetService("UserInputService")
local IsMobile = UserInputService.TouchEnabled

local Inventory = game.Players.LocalPlayer.PlayerGui:WaitForChild("Inventory")

if IsMobile == true then
	script.Parent.BoostsBackground.Size = UDim2.new(0.157, 0, 0.195, 0)
	script.Parent.ButtonsBackground.Size = UDim2.new(0.127, 0 ,0.357, 0)
	script.Parent.CurrenciesBackground.Size = UDim2.new(0.239, 0, 0.185, 0)
	script.Parent.LevelBarBackground.Size = UDim2.new(0.106, 0, 0.192, 0)
	script.Parent.TimeOfDayBackground.Size = UDim2.new(0.124, 0, 0.039, 0)
	Inventory.Hotbar.Size = UDim2.new(0.418, 0, 0.08, 0)
	
	script.Parent.BoostsBackground.Position.X.Offset = UDim2.new(-20)
	script.Parent.BoostsBackground.Position.Y.Offset = UDim2.new(-20)
	script.Parent.ButtonsBackground.Position.X.Offset = UDim2.new(-20)
	script.Parent.CurrenciesBackground.Position.X.Offset = UDim2.new(20)
	script.Parent.LevelBarBackground.Position.X.Offset = UDim2.new(-10)
	Inventory.Hotbar.Position.X.Offset = UDim2.new(-10)
end

Offset is immutable, and so is Scale, and X and Y, you need to do

pos = UDim2.new(pos.X.Scale, -10, pos.Y.Scale, pos.Y.Offset)

Works fine when I remove the loading screen from my game, by doesn’t when I add it back.

This is the script:

if IsMobile == true then
			game.Players.LocalPlayer.PlayerGui.Menu.ButtonsBackground:TweenPosition(UDim2.new(0.051, 0,0.543, 0), "Out", "Quint", 0)
			game.Players.LocalPlayer.PlayerGui.Menu.CurrenciesBackground:TweenPosition(UDim2.new(0.905, 0,0.484, 0), "Out", "Quint", 0)
			game.Players.LocalPlayer.PlayerGui.Menu.LevelBarBackground:TweenPosition(UDim2.new(0.005, 0, 0.859, 0), "Out", "Quint", 0)
			game.Players.LocalPlayer.PlayerGui.Inventory.Hotbar:TweenPosition(UDim2.new(0.5, 0,0.95, 0), "Out", "Quint", 0)
			game.Players.LocalPlayer.PlayerGui.SprintButton.SprintButton:TweenPosition(UDim2.new(0.9, 0,0.75, 0), "Out", "Quint", 0)
			game.Players.LocalPlayer.PlayerGui.Menu.BoostsBackground:TweenPosition(UDim2.new(0.05, 0, 0.847, 0), "Out", "Quint", 0)
			
			script.Parent.Parent.Parent.Menu.BoostsBackground.Position = UDim2.new(script.Parent.Parent.Parent.Menu.BoostsBackground.Position.X.Scale, 20, script.Parent.Parent.Parent.Menu.BoostsBackground.Position.Y.Scale, script.Parent.Parent.Parent.Menu.BoostsBackground.Position.Y.Offset)
			script.Parent.Parent.Parent.Menu.ButtonsBackground.Position = UDim2.new(script.Parent.Parent.Parent.Menu.ButtonsBackground.Position.X.Scale, 20, script.Parent.Parent.Parent.Menu.ButtonsBackground.Position.Y.Scale, script.Parent.Parent.Parent.Menu.ButtonsBackground.Position.Y.Offset)
			script.Parent.Parent.Parent.Menu.CurrenciesBackground.Position = UDim2.new(script.Parent.Parent.Parent.Menu.CurrenciesBackground.Position.X.Scale, -35, script.Parent.Parent.Parent.Menu.CurrenciesBackground.Position.Y.Scale, script.Parent.Parent.Parent.Menu.CurrenciesBackground.Position.Y.Offset)
			script.Parent.Parent.Parent.Menu.LevelBarBackground.Position = UDim2.new(script.Parent.Parent.Parent.Menu.LevelBarBackground.Position.X.Scale, 5, script.Parent.Parent.Parent.Menu.LevelBarBackground.Position.Y.Scale, -10)
			Inventory.Hotbar.Position = UDim2.new(Inventory.Hotbar.Position.X.Scale, 20, Inventory.Hotbar.Position.Y.Scale, Inventory.Hotbar.Position.Y.Offset)
			game.Players.LocalPlayer.PlayerGui.TestGUIs.AddExp.Position = UDim2.new(game.Players.LocalPlayer.PlayerGui.TestGUIs.AddExp.Position.X.Scale, -40, game.Players.LocalPlayer.PlayerGui.TestGUIs.AddExp.Position.Y.Scale, game.Players.LocalPlayer.PlayerGui.TestGUIs.AddExp.Position.Y.Offset)
		else
			game.Players.LocalPlayer.PlayerGui.Menu.ButtonsBackground:TweenPosition(UDim2.new(0.051, 0,0.543, 0), "Out", "Quint", 1)
			game.Players.LocalPlayer.PlayerGui.Menu.CurrenciesBackground:TweenPosition(UDim2.new(0.905, 0,0.484, 0), "Out", "Quint", 1)
			game.Players.LocalPlayer.PlayerGui.Menu.LevelBarBackground:TweenPosition(UDim2.new(0.005, 0, 0.859, 0), "Out", "Quint", 1)
			game.Players.LocalPlayer.PlayerGui.Inventory.Hotbar:TweenPosition(UDim2.new(0.5, 0,0.95, 0), "Out", "Quint", 1)
			game.Players.LocalPlayer.PlayerGui.SprintButton.SprintButton:TweenPosition(UDim2.new(0.9, 0,0.75, 0), "Out", "Quint", 1)
			game.Players.LocalPlayer.PlayerGui.Menu.BoostsBackground:TweenPosition(UDim2.new(0.05, 0, 0.847, 0), "Out", "Quint", 1)
		end
end

-- Reference to the Frame
local frame = script.Parent:WaitForChild("Frame")

-- Define the offset values
local offsetX = 50
local offsetY = 100

-- Set the Position property using UDim2.new with Offset
frame.Position = UDim2.new(0, offsetX, 0, offsetY)

-- Set the Size property using UDim2.new with Offset
frame.Size = UDim2.new(0, 200, 0, 300) -- Example size with offset values

This is very painful to read

You can’t change the offset by itself, use UDim2.new(0, offsetX, 0, offsetY) or UDim2.fromOffset(offsetX, offsetY)

We need to think about something to do our script idea

Sorry, I’m kinda a beginner I don’t know how I would do that.

script.Parent.BoostsBackground.Position = UDim2.fromOffset(-20, -20)