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
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)
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.
-- 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