-- Place this LocalScript in StarterGui
local TweenService = game:GetService("TweenService")
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
--------------------------------------------------------------------------------
-- Create the ScreenGui and Background Effects
--------------------------------------------------------------------------------
-- Create our main ScreenGui
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "ElementSelectUI"
screenGui.ResetOnSpawn = false
screenGui.Parent = playerGui
-- Create a blue background frame so the GUI feels integrated with the game’s tech theme.
local background = Instance.new("Frame")
background.Name = "Background"
background.Size = UDim2.new(1, 0, 1, 0)
background.BackgroundColor3 = Color3.fromRGB(0, 102, 204) -- A strong but techy blue
background.BackgroundTransparency = 0.2
background.Parent = screenGui
-- Add a BlurEffect to Lighting so the game world is blurred while the UI is active.
local blurEffect = Lighting:FindFirstChild("UIBlur")
if not blurEffect then
blurEffect = Instance.new("BlurEffect")
blurEffect.Name = "UIBlur"
blurEffect.Parent = Lighting
end
blurEffect.Size = 24
--------------------------------------------------------------------------------
-- Create the Main UI Frame and Element Buttons
--------------------------------------------------------------------------------
-- Create a centered container for our UI elements.
local mainFrame = Instance.new("Frame")
mainFrame.Name = "MainFrame"
mainFrame.Size = UDim2.new(0, 400, 0, 300)
mainFrame.AnchorPoint = Vector2.new(0.5, 0.5)
mainFrame.Position = UDim2.new(0.5, 0, 0.5, 0)
mainFrame.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
mainFrame.BackgroundTransparency = 0.1
mainFrame.BorderSizePixel = 0
mainFrame.Parent = screenGui
-- Title Label
local titleLabel = Instance.new("TextLabel")
titleLabel.Name = "TitleLabel"
titleLabel.Size = UDim2.new(1, 0, 0, 50)
titleLabel.Position = UDim2.new(0, 0, 0, 10)
titleLabel.BackgroundTransparency = 1
titleLabel.Text = "Choose Your Element"
titleLabel.Font = Enum.Font.SourceSansBold
titleLabel.TextScaled = true
titleLabel.TextColor3 = Color3.new(1, 1, 1)
titleLabel.Parent = mainFrame
-- Helper function to create an element button with a themed color.
local function createElementButton(elementName, color3, positionUDim2)
local button = Instance.new("TextButton")
button.Name = elementName.."Button"
button.Size = UDim2.new(0, 150, 0, 50)
button.Position = positionUDim2
button.BackgroundColor3 = color3
button.Text = elementName
button.Font = Enum.Font.SourceSans
button.TextScaled = true
button.TextColor3 = Color3.new(1, 1, 1)
button.Parent = mainFrame
return button
end
-- Calculate positions so that we have two rows of buttons.
local spacingX = 20
local startX = (400 - (2 * 150 + spacingX)) / 2 -- Center two side-by-side buttons
local startY = 80
local btnWater = createElementButton("Water", Color3.fromRGB(0, 150, 255), UDim2.new(0, startX, 0, startY))
local btnFire = createElementButton("Fire", Color3.fromRGB(255, 50, 0), UDim2.new(0, startX + 150 + spacingX, 0, startY))
local btnEarth = createElementButton("Earth", Color3.fromRGB(139, 69, 19), UDim2.new(0, startX, 0, startY + 60))
local btnAir = createElementButton("Air", Color3.fromRGB(200, 200, 255), UDim2.new(0, startX + 150 + spacingX, 0, startY + 60))
--------------------------------------------------------------------------------
-- Handle Element Selection and Animate Out the UI
--------------------------------------------------------------------------------
-- Function to be called when an element is chosen.
local function onElementChosen(element)
print("Element chosen: " .. element)
-- [Optional] You can store the chosen element on the player or in a module:
-- player:SetAttribute("ChosenElement", element)
-- Animate the UI fading out.
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local uiFadeTween = TweenService:Create(screenGui, tweenInfo, {["DisplayOrder"] = -1})
uiFadeTween:Play()
-- Tween the blur effect size down to 0 for a smooth transition back to game view.
local blurTween = TweenService:Create(blurEffect, tweenInfo, {Size = 0})
blurTween:Play()
-- When the tween is complete remove the UI.
uiFadeTween.Completed:Connect(function()
screenGui:Destroy()
end)
end
-- Connect button click events.
btnWater.MouseButton1Click:Connect(function() onElementChosen("Water") end)
btnFire.MouseButton1Click:Connect(function() onElementChosen("Fire") end)
btnEarth.MouseButton1Click:Connect(function() onElementChosen("Earth") end)
btnAir.MouseButton1Click:Connect(function() onElementChosen("Air") end)