I have 7 UI buttons, the first 6 works perfectly fine but when it comes to the last button, it doesnt act the way the others do, When I removed the 7th button, the same problem happens to the 6th button
the code for the buttons (I only used 1 code for all of them)
local GUI = script.Parent
local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local Buttons = GUI.Buttons:GetChildren()
local currentScreen = GUI.currentScreen
local gray = Color3.fromRGB(166, 166, 166)
local hidePOS = UDim2.new(1.363, 0, 0.5, 0)
local showPOS = UDim2.new(2.7, 0, 0.5, 0)
local tweenINFO = TweenInfo.new(0.3, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
local blurEffect = Lighting:FindFirstChild("ScreenBlur") or Instance.new("BlurEffect")
blurEffect.Name = "ScreenBlur"
blurEffect.Size = 0
blurEffect.Parent = Lighting
local function tweenTitle(title, position, transparency)
TweenService:Create(title, tweenINFO, {Position = position, TextTransparency = transparency}):Play()
end
local function resetButton(button)
button.UIStroke.Color = gray
button.ImageLabel.ImageColor3 = gray
button.isClicked.Value = false
tweenTitle(button.Title, hidePOS, 1)
end
local function resetAllButtons()
for _, button in pairs(Buttons) do
if button:IsA("ImageButton") then
resetButton(button)
end
end
end
local function tweenFOV(targetFOV)
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
if camera then
local fovTween = TweenService:Create(camera, TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {FieldOfView = targetFOV})
fovTween:Play()
end
end
local function tweenBlur(size)
TweenService:Create(blurEffect, TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = size}):Play()
end
for _, button in pairs(Buttons) do
if button:IsA("ImageButton") then
local isClicked = button:WaitForChild("isClicked")
local color = button:WaitForChild("SelectColor")
local uiStroke = button:WaitForChild("UIStroke")
local imageLabel = button:WaitForChild("ImageLabel")
local title = button:WaitForChild("Title")
button.MouseEnter:Connect(function()
uiStroke.Color = color.Value
imageLabel.ImageColor3 = color.Value
tweenTitle(title, showPOS, 0)
end)
button.MouseLeave:Connect(function()
if not isClicked.Value then
resetButton(button)
end
end)
button.MouseButton1Click:Connect(function()
isClicked.Value = true
currentScreen.Value = button.Name
tweenFOV(50)
tweenBlur(10)
for _, siblingButton in pairs(Buttons) do
if siblingButton:IsA("ImageButton") and siblingButton ~= button then
resetButton(siblingButton)
end
end
end)
end
end
currentScreen.Changed:Connect(function(newValue)
if newValue == "None" then
resetAllButtons()
tweenFOV(70)
tweenBlur(0)
end
end)
code for the screens that shows when the button is clicked
local GUI = script.Parent
local Panels = GUI.Panels
local currentSCREEN = GUI.currentScreen
local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local panelHidePOS = UDim2.new(0.5, 0, 0.8, 0)
local panelShowPOS = UDim2.new(0.5, 0, 0.5, 0)
local inFrame = false
local tweenINFO = TweenInfo.new(0.3, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
currentSCREEN.Changed:Connect(function(newVAL)
for _, v in pairs(Panels:GetChildren()) do
if v:IsA("Frame") then
if v.Name == newVAL then
v.Position = panelHidePOS
v.Rotation = 5
v.Visible = true
TweenService:Create(v, tweenINFO, { Position = panelShowPOS, Rotation = 0 }):Play()
else
TweenService:Create(v, tweenINFO, { Position = panelHidePOS, Rotation = 5 }):Play()
v.Visible = false
end
end
end
end)
local function isClickOnGUI()
local mousePosition = UIS:GetMouseLocation()
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
for _, gui in pairs(playerGui:GetDescendants()) do
if gui:IsA("GuiObject") and gui.Visible then
local guiPosition = gui.AbsolutePosition
local guiSize = gui.AbsoluteSize
if mousePosition.X >= guiPosition.X and mousePosition.X <= guiPosition.X + guiSize.X
and mousePosition.Y >= guiPosition.Y and mousePosition.Y <= guiPosition.Y + guiSize.Y then
return true
end
end
end
return false
end
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if not isClickOnGUI() then
currentSCREEN.Value = "None"
end
end
end)
robloxapp-20241223-1227342.wmv (1.5 MB)
I also tried it with just 1 button and the same problem occured