What do you want to achieve?
I want to make aesthetically pleasing GUIs. One way in which I am trying to do this is to make button animations for when a mouse starts and stops hovering over a button (also, does sizing GUIs using only their offsets make them square on some screens, but not on others? I’m worried my GUIs be misshapen sometimes).
What is the issue?
I keep getting the error “Unable to cast value to Object” which directs me to the Goals tables.
What solutions have you tried so far?
I tried being more specific with what I wanted to be tweened (for example, the script.Parent.Size.X used to be script.Parent.Size, but then I had to do X.Offset instead of just Offset in the Goals tables, which got rejected).
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Folder = ReplicatedStorage.Events -- Folder (not is use yet)
local Event = Folder.ColorEvent1 -- Remote event (not in use yet)
local function onMouseEntered()
local Information = TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local Goals = {Offset = 30}
local Tween1 = TweenService:Create(script.Parent.Size.X, Information, Goals)
local Tween2 = TweenService:Create(script.Parent.Size.Y, Information, Goals)
Tween1:Play()
Tween2:Play()
end
local function onMouseLeft()
local Information = TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local Goals = {Offset = 50}
local Tween1 = TweenService:Create(script.Parent.Size.X, Information, Goals)
local Tween2 = TweenService:Create(script.Parent.Size.Y, Information, Goals)
Tween1:Play()
Tween2:Play()
end
script.Parent.MouseEnter:Connect(onMouseEntered)
script.Parent.MouseLeave:Connect(onMouseLeft)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Folder = ReplicatedStorage.Events
local Event = Folder.ColorEvent1
local function onMouseEntered()
local Information = TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local Goals = UDim2.new{script.Parent.Size.X.Scale, 30, script.Parent.Size.Y.Scale, 30}
local Tween1 = TweenService:Create(script.Parent, Information, Goals)
Tween1:Play()
end
local function onMouseLeft()
local Information = TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local Goals = UDim2.new{script.Parent.Size.X.Scale, 50, script.Parent.Size.Y.Scale, 50}
local Tween1 = TweenService:Create(script.Parent, Information, Goals)
Tween1:Play()
end
script.Parent.MouseEnter:Connect(onMouseEntered)
script.Parent.MouseLeave:Connect(onMouseLeft)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Folder = ReplicatedStorage.Events
local Event = Folder.ColorEvent1
local function onMouseEntered()
local Information = TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local Goals = {Size = UDim2.new(script.Parent.Size.X.Scale, 30, script.Parent.Size.Y.Scale, 30)}
local Tween1 = TweenService:Create(script.Parent, Information, Goals)
Tween1:Play()
end
local function onMouseLeft()
local Information = TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
local Goals = {Size = UDim2.new(script.Parent.Size.X.Scale, 50, script.Parent.Size.Y.Scale, 50)}
local Tween1 = TweenService:Create(script.Parent, Information, Goals)
Tween1:Play()
end
script.Parent.MouseEnter:Connect(onMouseEntered)
script.Parent.MouseLeave:Connect(onMouseLeft)
Thanks for the help! Also, I was also wondering if resizing GUIs using offsets only make the proportions different on screens with different size rations. Does it produce that issue?
I would suggest using scale and barely using offset.
Offset
Sized by the pixels of a device meaning some devices will have the UI bigger than their screen and other smaller than their mouse.
Scale
Sized by the percentage of their screen meaning it will fit all screens but will change width/height. This is easily fixed with UIAspectRatio which locks the size and just sizes it with both X and Y.
Would keeping the GUIs square if necessary be unusually difficult? Also, where can the UI Aspect Ratio property be found (for example, can it be found in Text Buttons)?
UIAspectRatio is an object which you must add like any other object and can only be used for any UI object, not 3D. This object must be placed in the object that you wish to lock its size from being changed on 1 axis.
Though sometimes you must tweak the aspect value which can be difficult so I suggest using a plugin that automatically does this for you.