Plugin Support - Creating an Auto Scale plugin

I am probably the 20,000th person to attempt this, but I’m trying to create an auto-scale plugin. I am encountering a few errors; how do I fix them?

-- toolbar locals

local toolbar = plugin:CreateToolbar("OxyScale V1")
local selection = game:GetService("Selection")
local history = game:GetService("ChangeHistoryService")

-- functions

function waypoint()
	history:SetWaypoint("ScaleHistory")
end

function button(name, desc, image, funct)
	local newbutton = toolbar:CreateButton(name, desc, image)
	newbutton.Click:Connect(function()
		waypoint()
		print("button clicked with function", funct)
		if funct == "ScaleSelectedUI" then
			local selectedObjects = selection:Get()

			for index, selected in pairs(selectedObjects) do
				if selected:IsA("GuiObject") then
					print(selected, "is a gui object")

					selected.Size = selected.Size * UDim2.new(1.5, 0, 1.5, 0)
				end
			end
		end
		waypoint()
	end)
end

-- event firing

button(
	"Open Menu",
	"Open the main menu.",
	"rbxassetid://16155692094",
	"OpenMainMenu"
)
button(
	"Scale Selected",
	"Ensure you select any UI elements you wish to scale, after clicking this button to auto-scale the selected elements.",
	"rbxassetid://16155692094",
	"ScaleSelectedUI"
)
  20:22:33.683  user_OxyScale.lua.Script:25: attempt to perform arithmetic (mul) on UDim2  -  Edit
2 Likes

Do it like this:

selected.Size = UDim2.new(selected.Size.X.Scale * 1.5, selected.Size.X.Offset, selected.Size.Y.Scale * 1.5, selected.Size.Y.Offset
1 Like

Are you sure this isn’t AI generated? I tried to use AI myself and it gave me the same line of code.

Anyways, I have tried this and it doesn’t change any property at all.

Thanks for the assumption, but I didn’t use AI, I found a post relating to it

or as someone else mentioned you can use Udim2.fromScale

Another method I’ve tried that isn’t working.

Have you tried to extract the dimensions from the UDim2, perform the multiplication, and then create a new UDim2 with the values?

selected.Size = UDim2.new(
    selected.Size.X.Scale * 1.5,
    selected.Size.X.Offset * 1.5,
    selected.Size.Y.Scale * 1.5,
    selected.Size.Y.Offset * 1.5
)

This works, however it makes the frame bigger when re-scaled.

I would like it to ensure the UI is always auto-scaled based on each players screen resolution.

Ah I see This will set the Size separately for width and height without directly trying to multiply a UDim2 object. This should prevent errors related to UDim2 .

-- Function to scale a UI element by a specified factor
function scaleUI(UI, scaleFactor)
    -- Get the size of the player's screen (relative to the PlayerGui element)
    local screenSize = game.Players.LocalPlayer:GetMouse().ViewportSize
    
    -- Calculate the new width and height based on the screen size and scaling factor
    local newWidth = screenSize.X * scaleFactor
    local newHeight = screenSize.Y * scaleFactor
    
    -- Set the new size for the UI element separately for width and height
    UI.Size = UDim2.new(0, newWidth, 0, newHeight)
end

-- Example usage with a Frame
local Frame = Instance.new("Frame")
Frame.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui") -- Assuming it's a child of PlayerGui

-- Scale the Frame using relative sizing to 150% of the screen width and height
scaleUI(Frame, 1.5)

I would like it so when i click the scale button with a roblox plugin, it scales it through there without having to play the game or anything.

How would I do this?

You’d have to find the GUI you want to edit which you already have done

			for index, selected in pairs(selectedObjects) do
				if selected:IsA("GuiObject") then
					print(selected, "is a gui object")

You’d then have to have to have it so when you click the scale button it scales it, using the method I gave above or any other method that will properly scale it.

I’d also add a way for you to easily change the scale factor.

This method is fully configured, there is just one line that returns errors.

local screenSize = game.Players.LocalPlayer:GetMouse().ViewportSize
  21:21:18.792  ViewportSize is not a valid member of PlayerMouse "Instance"  -  Client - LocalScript:1

Whole script

-- toolbar locals

local toolbar = plugin:CreateToolbar("OxyScale V1")
local selection = game:GetService("Selection")
local history = game:GetService("ChangeHistoryService")

-- functions

function waypoint()
	history:SetWaypoint("ScaleHistory")
end

function scaleUI(UI, scaleFactor)
	local screenSize = game.Players.LocalPlayer:GetMouse().ViewportSize
	local newWidth = screenSize.X * scaleFactor
	local newHeight = screenSize.Y * scaleFactor
	UI.Size = UDim2.new(0, newWidth, 0, newHeight)
end

function button(name, desc, image, funct)
	local newbutton = toolbar:CreateButton(name, desc, image)
	newbutton.Click:Connect(function()
		waypoint()
		print("button clicked with function", funct)
		if funct == "ScaleSelectedUI" then
			local selectedObjects = selection:Get()

			for index, selected in pairs(selectedObjects) do
				if selected:IsA("GuiObject") then
					print(selected, "is a gui object")

					scaleUI(selected, 1.5)
				end
			end
		end
		waypoint()
	end)
end

-- event firing

button(
	"Open Menu",
	"Open the main menu.",
	"rbxassetid://16155692094",
	"OpenMainMenu"
)
button(
	"Scale Selected",
	"Ensure you select any UI elements you wish to scale, after clicking this button to auto-scale the selected elements.",
	"rbxassetid://16155692094",
	"ScaleSelectedUI"
)

Oh my bad we need to use the UserInputService to get the ViewportSize. The ViewportSize is not accessible through GetMouse() on the Player I forgot about that.

function scaleUI(UI, scaleFactor)
    local player = game.Players.LocalPlayer
    local mouse = player:GetMouse()
    local inputService = game:GetService("UserInputService")

    local screenSize = inputService:GetViewSize()
    local newWidth = screenSize.X * scaleFactor
    local newHeight = screenSize.Y * scaleFactor
    UI.Size = UDim2.new(0, newWidth, 0, newHeight)
end

This is supposed to be for a plugin, not a LocalScript…

  22:18:52.401  GetViewSize is not a valid member of UserInputService "UserInputService"  -  Edit
1 Like

image

it’s workspace.CurrentCamera.ViewportSize btw

2 Likes

Using this, I fired the event and the UI size went from {0, 745},{0, 416} to {0, 2037},{0, 1080}

It should be some sort of decimal number.

A plugin script is a server script that is then saved as a local plugin through roblox to act as if it’s a public plugin.