I have a script which pops up UI, which is a save selection UI. When this pops up, this script I have will make the saveselection frame enlarge when hovering. However I am trying to make it so when it is selected it will get larger and the uistroke border will turn orange. This will not go away until you either click another frame, or click out of any frames.
Here is my script:
-- Necessary service
local TweenService = game:GetService("TweenService")
-- Variables for SaveDataSelection UI
local saveSelectFrame = script.Parent.SaveSelectFrame
local savesFrame = saveSelectFrame.Saves
-- Save folders
local save1 = savesFrame:FindFirstChild("Save1")
local save2 = savesFrame:FindFirstChild("Save2")
local save3 = savesFrame:FindFirstChild("Save3")
-- Tween Info for scaling
local scaleTweenInfo = TweenInfo.new(
0.2, -- Duration in seconds
Enum.EasingStyle.Quad, -- Easing style
Enum.EasingDirection.InOut, -- Easing direction
0, -- Number of times to repeat
false, -- Reverse tween
0 -- Delay time
)
-- Tween Info for position
local positionTweenInfo = TweenInfo.new(
.2, -- Duration in seconds
Enum.EasingStyle.Bounce, -- Easing style
Enum.EasingDirection.InOut, -- Easing direction
0, -- Number of times to repeat
false, -- Reverse tween
0 -- Delay time
)
-- Table to store original sizes, positions, and anchor points
local originalProperties = {}
-- Function to save original sizes, positions, and anchor points
local function saveOriginalProperties(frame)
if not originalProperties[frame] then
originalProperties[frame] = {
Size = frame.Size,
Position = frame.Position,
AnchorPoint = frame.AnchorPoint,
Adjusted = false -- Added flag to track if anchor position has already been adjusted
}
end
end
-- Function to adjust the position for center scaling (0.5, 0.5 anchor point)
local function adjustPositionForCenter(frame)
local originalProps = originalProperties[frame]
-- Only adjust the position once if it hasn't already been done
if not originalProps.Adjusted and originalProps.AnchorPoint ~= Vector2.new(0.5, 0.5) then
-- Calculate the offset caused by the change in anchor point
local anchorOffset = (Vector2.new(0.5, 0.5) - originalProps.AnchorPoint) * frame.AbsoluteSize
frame.Position = frame.Position + UDim2.new(0, anchorOffset.X, 0, anchorOffset.Y)
frame.AnchorPoint = Vector2.new(0.5, 0.5)
originalProps.Adjusted = true -- Mark it as adjusted so we don't adjust again
end
end
-- Function to create and play a tween for scaling up from the center
local function scaleUp(frame)
-- Save original properties
saveOriginalProperties(frame)
-- Adjust position for center scaling (if not already done)
adjustPositionForCenter(frame)
-- Tween the size
local newSize = UDim2.new(
frame.Size.X.Scale * 1.1,
frame.Size.X.Offset * 1.1,
frame.Size.Y.Scale * 1.1,
frame.Size.Y.Offset * 1.1
)
local tweenGoal = {Size = newSize}
local tween = TweenService:Create(frame, scaleTweenInfo, tweenGoal)
tween:Play()
end
-- Function to create and play a tween for scaling down to original size
local function scaleDown(frame)
-- Restore original properties
local originalProps = originalProperties[frame]
-- Tween the size back to the original
local tweenGoal = {Size = originalProps.Size}
local tween = TweenService:Create(frame, scaleTweenInfo, tweenGoal)
tween:Play()
end
-- Function to move a frame from the bottom of the screen and then tween it back
local function moveFromBottomAndTween(frame)
-- Save original properties
saveOriginalProperties(frame)
-- Move the frame to the bottom middle of the screen (adjusted to be off-screen)
frame.Position = UDim2.new(0.5, 0, 1.5, 0) -- Adjust this as needed
-- Tween the frame to its original position
local tweenGoal = {Position = originalProperties[frame].Position}
local tween = TweenService:Create(frame, positionTweenInfo, tweenGoal)
tween:Play()
end
-- Function to setup hover effects for a frame
local function setupHoverEffects(frame)
-- Save original properties
saveOriginalProperties(frame)
-- Connect the MouseEnter event to scale up
frame.MouseEnter:Connect(function()
scaleUp(frame)
end)
-- Connect the MouseLeave event to scale down
frame.MouseLeave:Connect(function()
scaleDown(frame)
end)
end
-- Function to apply hover effects to all children of a folder
local function setupHoverEffectsForFolder(folder)
if not folder then return end
for _, child in ipairs(folder:GetChildren()) do
if child:IsA("Frame") or child:IsA("TextButton") or child:IsA("ImageButton") then
setupHoverEffects(child)
end
end
end
-- Function to handle button click and change border color
local function onButtonClick()
local save1Border = savesFrame:FindFirstChild("Save1-Border")
if save1Border and save1Border:FindFirstChild("UIStroke") then
local uiStroke = save1Border.UIStroke
uiStroke.Color = Color3.fromRGB(255, 165, 0) -- Orange color
end
end
-- Function to start the tweening process with a delay
local function startTweeningWithDelay()
wait(20) -- Wait for 20 seconds before starting the tweening
-- Tween all frames within the folders
if save1 then moveFromBottomAndTween(save1) end
if save2 then moveFromBottomAndTween(save2) end
if save3 then moveFromBottomAndTween(save3) end
end
-- Connect the ClickDetect button click event
local clickDetect = savesFrame:FindFirstChild("Save1-Middle"):FindFirstChild("ClickDetect")
if clickDetect then
clickDetect.MouseButton1Click:Connect(onButtonClick)
end
-- Apply hover effects to all save folders
setupHoverEffectsForFolder(save1)
setupHoverEffectsForFolder(save2)
setupHoverEffectsForFolder(save3)
-- Start the tweening process with a delay
startTweeningWithDelay()
Here is the layout:
thanks for any help! :]
reply with any other things needed to help solve this