I have 2 LocalScripts that I use to Open and Close a ScreenGui called ShopUi, this works perfectly with no issues but after making another Menu Popup called SettingsUi and duplicating everything correctly it just doesn’t work no errors or anything, and even with my limited understanding of Lua I know this shouldn’t be happening.
Even weirder, the first time I duplicated the scripts the one in SettingsUi worked fine when the one in the Settings button didn’t. So this is all wizardry for me as why something that worked one time stops working the second time, I maybe missed something but right now I’m lost.
The original scripts for the ShopUi:
In the Shop button:
local button = script.Parent
local ShopUi = game.Players.LocalPlayer.PlayerGui:FindFirstChild("ShopUi")
local Main = ShopUi and ShopUi:FindFirstChild("Main")
local TweenService = game:GetService("TweenService")
local originalPosition = Main and Main.Position or UDim2.new(0, 0, 0, 0)
local animationPlaying = false
local function createBounceAnimation(target, info)
local tweenInfo = TweenInfo.new(
info.Time,
Enum.EasingStyle.Back,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = TweenService:Create(target, tweenInfo, info.Properties)
return tween
end
if Main then
Main.Position = UDim2.new(
originalPosition.X.Scale,
originalPosition.X.Offset,
originalPosition.Y.Scale,
originalPosition.Y.Offset + 500
)
end
local function onButtonClick()
if not animationPlaying and Main then
animationPlaying = true
local newYOffset = Main.Position.Y.Offset > originalPosition.Y.Offset and -500 or 500
local animationInfo = {
Time = 0.5,
Properties = {
Position = UDim2.new(
originalPosition.X.Scale,
originalPosition.X.Offset,
originalPosition.Y.Scale,
Main.Position.Y.Offset + newYOffset
)
}
}
local animation = createBounceAnimation(Main, animationInfo)
animation:Play()
animation.Completed:Connect(function()
animationPlaying = false
end)
end
end
button.MouseButton1Click:Connect(onButtonClick)
And in the ShopUi:
local button = script.Parent
local ShopUi = game.Players.LocalPlayer.PlayerGui:FindFirstChild("ShopUi")
local Main = ShopUi and ShopUi:FindFirstChild("Main")
local TweenService = game:GetService("TweenService")
local originalPosition = Main and Main.Position or UDim2.new(0, 0, 0, 0)
local animationPlaying = false
local function createBounceAnimation(target, info)
local tweenInfo = TweenInfo.new(
info.Time,
Enum.EasingStyle.Back,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = TweenService:Create(target, tweenInfo, info.Properties)
return tween
end
local function onButtonClick()
if not animationPlaying and Main then
animationPlaying = true
local newYOffset = 500
local animationInfo = {
Time = 0.5,
Properties = {
Position = UDim2.new(
originalPosition.X.Scale,
originalPosition.X.Offset,
originalPosition.Y.Scale,
Main.Position.Y.Offset + newYOffset
)
}
}
local animation = createBounceAnimation(Main, animationInfo)
animation:Play()
animation.Completed:Connect(function()
animationPlaying = false
Main.Position = UDim2.new(originalPosition.X.Scale, originalPosition.X.Offset, originalPosition.Y.Scale, originalPosition.Y.Offset + newYOffset)
end)
end
end
button.MouseButton1Click:Connect(onButtonClick)
And now are the duplicated script with ShopUi changed to SettingsUi:
In the settings button:
local button = script.Parent
local SettingsUi = game.Players.LocalPlayer.PlayerGui:FindFirstChild("SettingsUi")
local Main = SettingsUi and SettingsUi:FindFirstChild("Main")
local TweenService = game:GetService("TweenService")
local originalPosition = Main and Main.Position or UDim2.new(0, 0, 0, 0)
local animationPlaying = false
local function createBounceAnimation(target, info)
local tweenInfo = TweenInfo.new(
info.Time,
Enum.EasingStyle.Back,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = TweenService:Create(target, tweenInfo, info.Properties)
return tween
end
if Main then
Main.Position = UDim2.new(
originalPosition.X.Scale,
originalPosition.X.Offset,
originalPosition.Y.Scale,
originalPosition.Y.Offset + 500
)
end
local function onButtonClick()
if not animationPlaying and Main then
animationPlaying = true
local newYOffset = Main.Position.Y.Offset > originalPosition.Y.Offset and -500 or 500
local animationInfo = {
Time = 0.5,
Properties = {
Position = UDim2.new(
originalPosition.X.Scale,
originalPosition.X.Offset,
originalPosition.Y.Scale,
Main.Position.Y.Offset + newYOffset
)
}
}
local animation = createBounceAnimation(Main, animationInfo)
animation:Play()
animation.Completed:Connect(function()
animationPlaying = false
end)
end
end
button.MouseButton1Click:Connect(onButtonClick)
And in the SettingsUi:
local button = script.Parent
local SettingsUi = game.Players.LocalPlayer.PlayerGui:FindFirstChild("SettingsUi")
local Main = SettingsUi and SettingsUi:FindFirstChild("Main")
local TweenService = game:GetService("TweenService")
local originalPosition = Main and Main.Position or UDim2.new(0, 0, 0, 0)
local animationPlaying = false
local function createBounceAnimation(target, info)
local tweenInfo = TweenInfo.new(
info.Time,
Enum.EasingStyle.Back,
Enum.EasingDirection.Out,
0,
false,
0
)
local tween = TweenService:Create(target, tweenInfo, info.Properties)
return tween
end
local function onButtonClick()
if not animationPlaying and Main then
animationPlaying = true
local newYOffset = 500
local animationInfo = {
Time = 0.5,
Properties = {
Position = UDim2.new(
originalPosition.X.Scale,
originalPosition.X.Offset,
originalPosition.Y.Scale,
Main.Position.Y.Offset + newYOffset
)
}
}
local animation = createBounceAnimation(Main, animationInfo)
animation:Play()
animation.Completed:Connect(function()
animationPlaying = false
Main.Position = UDim2.new(originalPosition.X.Scale, originalPosition.X.Offset, originalPosition.Y.Scale, originalPosition.Y.Offset + newYOffset)
end)
end
end
button.MouseButton1Click:Connect(onButtonClick)
And here is the Hierarchy of my Ui: