1
This commit is contained in:
commit
a85391509d
211 files changed
+28903
No files matched your search
@@ -0,0 +1,379 @@
|
||||
--!strict
|
||||
-- LocalScript in StarterPlayerScripts.
|
||||
-- Main menu shown when the player joins: pick a game mode and customize the weapon,
|
||||
-- then press "Play" to spawn into the map with that loadout. "Play" fires
|
||||
-- ReplicatedStorage.RequestSpawn; the server (EquipRifle) loads the character and equips
|
||||
-- the rifle. The chosen sight is sent to the server through ReplicatedStorage.RifleSight
|
||||
-- (RifleSights keeps it on the player and applies it to every new rifle).
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local TweenService = game:GetService("TweenService")
|
||||
|
||||
local player = Players.LocalPlayer
|
||||
local playerGui = player:WaitForChild("PlayerGui")
|
||||
|
||||
local requestSpawn = ReplicatedStorage:WaitForChild("RequestSpawn") :: RemoteEvent
|
||||
local sightRemote = ReplicatedStorage:WaitForChild("RifleSight") :: RemoteEvent
|
||||
local sights = ReplicatedStorage:WaitForChild("RifleParts"):WaitForChild("Sights")
|
||||
local rifleTemplate = ReplicatedStorage:WaitForChild("SniperViewmodel") :: Model
|
||||
|
||||
-- ---------------------------------------------------------------- theme
|
||||
local DARK = Color3.fromRGB(14, 14, 20)
|
||||
local PANEL = Color3.fromRGB(23, 23, 33)
|
||||
local PANEL_LIGHT = Color3.fromRGB(30, 30, 42)
|
||||
local ACCENT = Color3.fromRGB(255, 200, 40)
|
||||
local ACCENT_DIM = Color3.fromRGB(120, 96, 24)
|
||||
local TEXT = Color3.fromRGB(238, 238, 244)
|
||||
local MUTED = Color3.fromRGB(150, 150, 168)
|
||||
local OUTLINE = Color3.fromRGB(10, 10, 14)
|
||||
local FONT = Enum.Font.GothamBold
|
||||
|
||||
local MODES = { "Free Roam", "Hunt", "Elimination" }
|
||||
local SIGHTS = { "Iron", "RedDot", "Scope" }
|
||||
|
||||
local chosenMode = MODES[1]
|
||||
local chosenSight = SIGHTS[1]
|
||||
|
||||
-- ---------------------------------------------------------------- gui
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "MainMenu"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.DisplayOrder = 100
|
||||
gui.IgnoreGuiInset = true
|
||||
gui.Parent = playerGui
|
||||
|
||||
local backdrop = Instance.new("Frame")
|
||||
backdrop.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
backdrop.Position = UDim2.fromScale(0.5, 0.5)
|
||||
backdrop.Size = UDim2.fromScale(1, 1)
|
||||
backdrop.BackgroundColor3 = DARK
|
||||
backdrop.BackgroundTransparency = 0.08
|
||||
backdrop.Parent = gui
|
||||
|
||||
local title = Instance.new("TextLabel")
|
||||
title.AnchorPoint = Vector2.new(0.5, 0)
|
||||
title.Position = UDim2.fromScale(0.5, 0.08)
|
||||
title.Size = UDim2.fromOffset(600, 90)
|
||||
title.BackgroundTransparency = 1
|
||||
title.Font = Enum.Font.GothamBlack
|
||||
title.Text = "HUNTER"
|
||||
title.TextSize = 62
|
||||
title.TextColor3 = TEXT
|
||||
title.TextStrokeTransparency = 0.6
|
||||
title.Parent = gui
|
||||
local titleShadow = Instance.new("UIStroke")
|
||||
titleShadow.Color = OUTLINE
|
||||
titleShadow.Thickness = 2
|
||||
titleShadow.Parent = title
|
||||
|
||||
local subtitle = Instance.new("TextLabel")
|
||||
subtitle.AnchorPoint = Vector2.new(0.5, 0)
|
||||
subtitle.Position = UDim2.fromScale(0.5, 0.165)
|
||||
subtitle.Size = UDim2.fromOffset(600, 40)
|
||||
subtitle.BackgroundTransparency = 1
|
||||
subtitle.Font = Enum.Font.Gotham
|
||||
subtitle.Text = "Choose your hunt"
|
||||
subtitle.TextSize = 18
|
||||
subtitle.TextColor3 = MUTED
|
||||
subtitle.Parent = gui
|
||||
|
||||
-- a helper for a rounded panel with a soft border
|
||||
local function panel(parent: Instance): Frame
|
||||
local f = Instance.new("Frame")
|
||||
f.BackgroundColor3 = PANEL
|
||||
f.Parent = parent
|
||||
local corner = Instance.new("UICorner")
|
||||
corner.CornerRadius = UDim.new(0, 14)
|
||||
corner.Parent = f
|
||||
local stroke = Instance.new("UIStroke")
|
||||
stroke.Color = OUTLINE
|
||||
stroke.Thickness = 2
|
||||
stroke.Parent = f
|
||||
return f
|
||||
end
|
||||
|
||||
local function sectionLabel(parent: Instance, text: string): TextLabel
|
||||
local l = Instance.new("TextLabel")
|
||||
l.BackgroundTransparency = 1
|
||||
l.Font = FONT
|
||||
l.Text = text
|
||||
l.TextSize = 15
|
||||
l.TextColor3 = ACCENT
|
||||
l.TextXAlignment = Enum.TextXAlignment.Left
|
||||
l.Parent = parent
|
||||
return l
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------- game mode column
|
||||
local modePanel = panel(gui)
|
||||
modePanel.AnchorPoint = Vector2.new(0, 0.5)
|
||||
modePanel.Position = UDim2.fromScale(0.07, 0.55)
|
||||
modePanel.Size = UDim2.fromOffset(360, 460)
|
||||
modePanel.Parent = gui
|
||||
local modeLayout = Instance.new("UIListLayout")
|
||||
modeLayout.Padding = UDim.new(0, 12)
|
||||
modeLayout.SortOrder = Enum.SortOrder.LayoutOrder
|
||||
modeLayout.Parent = modePanel
|
||||
local modePad = Instance.new("UIPadding")
|
||||
modePad.PaddingLeft = UDim.new(0, 22)
|
||||
modePad.PaddingRight = UDim.new(0, 22)
|
||||
modePad.PaddingTop = UDim.new(0, 22)
|
||||
modePad.PaddingBottom = UDim.new(0, 22)
|
||||
modePad.Parent = modePanel
|
||||
sectionLabel(modePanel, "GAME MODE").LayoutOrder = 0
|
||||
|
||||
local modeButtons: { [string]: Frame } = {}
|
||||
local function buildModeButtons()
|
||||
for i, name in MODES do
|
||||
local b = Instance.new("Frame")
|
||||
b.Name = name
|
||||
b.Size = UDim2.fromOffset(316, 110)
|
||||
b.BackgroundColor3 = PANEL_LIGHT
|
||||
b.LayoutOrder = i
|
||||
local corner = Instance.new("UICorner")
|
||||
corner.CornerRadius = UDim.new(0, 10)
|
||||
corner.Parent = b
|
||||
local stroke = Instance.new("UIStroke")
|
||||
stroke.Color = OUTLINE
|
||||
stroke.Thickness = 2
|
||||
stroke.Parent = b
|
||||
local icon = Instance.new("Frame")
|
||||
icon.Size = UDim2.fromOffset(54, 54)
|
||||
icon.Position = UDim2.new(0, 18, 0.5, -27)
|
||||
icon.BackgroundColor3 = ACCENT
|
||||
icon.BackgroundTransparency = 0.15
|
||||
icon.Parent = b
|
||||
local ic = Instance.new("UICorner")
|
||||
ic.CornerRadius = UDim.new(0, 8)
|
||||
ic.Parent = icon
|
||||
local title2 = Instance.new("TextLabel")
|
||||
title2.Position = UDim2.new(0, 86, 0, 22)
|
||||
title2.Size = UDim2.fromOffset(210, 30)
|
||||
title2.BackgroundTransparency = 1
|
||||
title2.Font = FONT
|
||||
title2.Text = name
|
||||
title2.TextSize = 22
|
||||
title2.TextColor3 = TEXT
|
||||
title2.TextXAlignment = Enum.TextXAlignment.Left
|
||||
title2.Parent = b
|
||||
local desc = Instance.new("TextLabel")
|
||||
desc.Position = UDim2.new(0, 86, 0, 56)
|
||||
desc.Size = UDim2.fromOffset(210, 34)
|
||||
desc.BackgroundTransparency = 1
|
||||
desc.Font = Enum.Font.Gotham
|
||||
desc.Text = if name == "Free Roam" then "Explore and hunt freely"
|
||||
elseif name == "Hunt" then "Hunt the target bots"
|
||||
else "Last one standing"
|
||||
desc.TextSize = 13
|
||||
desc.TextColor3 = MUTED
|
||||
desc.TextXAlignment = Enum.TextXAlignment.Left
|
||||
desc.TextWrapped = true
|
||||
desc.Parent = b
|
||||
local check = Instance.new("TextLabel")
|
||||
check.Name = "Check"
|
||||
check.AnchorPoint = Vector2.new(1, 0.5)
|
||||
check.Position = UDim2.new(1, -16, 0.5, 0)
|
||||
check.Size = UDim2.fromOffset(30, 30)
|
||||
check.BackgroundTransparency = 1
|
||||
check.Font = FONT
|
||||
check.Text = "✓"
|
||||
check.TextSize = 26
|
||||
check.TextColor3 = ACCENT
|
||||
check.Visible = false
|
||||
check.Parent = b
|
||||
local btn = Instance.new("TextButton")
|
||||
btn.Size = UDim2.fromScale(1, 1)
|
||||
btn.BackgroundTransparency = 1
|
||||
btn.Text = ""
|
||||
btn.Parent = b
|
||||
btn.MouseButton1Click:Connect(function()
|
||||
chosenMode = name
|
||||
for _, other in modeButtons do
|
||||
other.BackgroundColor3 = PANEL_LIGHT
|
||||
other:FindFirstChild("Check").Visible = false
|
||||
end
|
||||
b.BackgroundColor3 = ACCENT_DIM
|
||||
check.Visible = true
|
||||
end)
|
||||
b.Parent = modePanel
|
||||
modeButtons[name] = b
|
||||
end
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------- weapon column
|
||||
local weaponPanel = panel(gui)
|
||||
weaponPanel.AnchorPoint = Vector2.new(1, 0.5)
|
||||
weaponPanel.Position = UDim2.fromScale(0.93, 0.55)
|
||||
weaponPanel.Size = UDim2.fromOffset(360, 460)
|
||||
weaponPanel.Parent = gui
|
||||
local weaponLayout = Instance.new("UIListLayout")
|
||||
weaponLayout.Padding = UDim.new(0, 12)
|
||||
weaponLayout.SortOrder = Enum.SortOrder.LayoutOrder
|
||||
weaponLayout.Parent = weaponPanel
|
||||
local weaponPad = Instance.new("UIPadding")
|
||||
weaponPad.PaddingLeft = UDim.new(0, 22)
|
||||
weaponPad.PaddingRight = UDim.new(0, 22)
|
||||
weaponPad.PaddingTop = UDim.new(0, 22)
|
||||
weaponPad.PaddingBottom = UDim.new(0, 22)
|
||||
weaponPad.Parent = weaponPanel
|
||||
sectionLabel(weaponPanel, "WEAPON — Sniper Rifle").LayoutOrder = 0
|
||||
|
||||
-- rifle preview in a ViewportFrame (the template with the chosen sight applied)
|
||||
local preview = Instance.new("ViewportFrame")
|
||||
preview.Size = UDim2.fromOffset(316, 170)
|
||||
preview.BackgroundColor3 = PANEL_LIGHT
|
||||
preview.LayoutOrder = 1
|
||||
preview.Ambient = Color3.fromRGB(190, 190, 205)
|
||||
preview.LightColor = Color3.new(1, 1, 1)
|
||||
preview.LightDirection = Vector3.new(-0.3, -1, -0.5)
|
||||
local previewCorner = Instance.new("UICorner")
|
||||
previewCorner.CornerRadius = UDim.new(0, 10)
|
||||
previewCorner.Parent = preview
|
||||
preview.Parent = weaponPanel
|
||||
|
||||
local previewModel: Model = rifleTemplate:Clone()
|
||||
for _, d in previewModel:GetDescendants() do
|
||||
if d:IsA("BasePart") then
|
||||
d.Anchored = true
|
||||
d.CastShadow = false
|
||||
end
|
||||
end
|
||||
previewModel.Parent = preview
|
||||
local previewCam = Instance.new("Camera")
|
||||
previewCam.FieldOfView = 18
|
||||
previewCam.Parent = preview
|
||||
preview.CurrentCamera = previewCam
|
||||
|
||||
local function applyPreviewSight()
|
||||
local old = previewModel:FindFirstChild("Sight")
|
||||
if old then
|
||||
old:Destroy()
|
||||
end
|
||||
local source = sights:FindFirstChild(chosenSight)
|
||||
if not source or not source:IsA("Model") then
|
||||
return
|
||||
end
|
||||
local sight = source:Clone()
|
||||
sight.Name = "Sight"
|
||||
sight:PivotTo(previewModel:GetPivot())
|
||||
for _, d in sight:GetDescendants() do
|
||||
if d:IsA("BasePart") then
|
||||
d.Anchored = true
|
||||
d.CastShadow = false
|
||||
end
|
||||
end
|
||||
sight.Parent = previewModel
|
||||
-- frame the rifle in the preview
|
||||
previewModel.WorldPivot = CFrame.new(previewModel:GetPivot().Position)
|
||||
local cf, size = previewModel:GetBoundingBox()
|
||||
local halfTan = math.tan(math.rad(previewCam.FieldOfView / 2))
|
||||
local dist = math.max((size.X / 2) / (halfTan * 316 / 170), (size.Y / 2) / halfTan) * 1.1 + size.Z / 2
|
||||
previewCam.CFrame = CFrame.lookAt(cf.Position + Vector3.zAxis * dist, cf.Position)
|
||||
end
|
||||
|
||||
local sightLabel = Instance.new("TextLabel")
|
||||
sightLabel.BackgroundTransparency = 1
|
||||
sightLabel.Font = FONT
|
||||
sightLabel.Text = "SIGHT"
|
||||
sightLabel.TextSize = 14
|
||||
sightLabel.TextColor3 = MUTED
|
||||
sightLabel.TextXAlignment = Enum.TextXAlignment.Left
|
||||
sightLabel.LayoutOrder = 2
|
||||
sightLabel.Parent = weaponPanel
|
||||
|
||||
local sightRow = Instance.new("Frame")
|
||||
sightRow.Size = UDim2.fromOffset(316, 56)
|
||||
sightRow.BackgroundTransparency = 1
|
||||
sightRow.LayoutOrder = 3
|
||||
sightRow.Parent = weaponPanel
|
||||
local sightLayout = Instance.new("UIListLayout")
|
||||
sightLayout.FillDirection = Enum.FillDirection.Horizontal
|
||||
sightLayout.Padding = UDim.new(0, 10)
|
||||
sightLayout.SortOrder = Enum.SortOrder.LayoutOrder
|
||||
sightLayout.Parent = sightRow
|
||||
|
||||
local sightButtons: { [string]: TextButton } = {}
|
||||
local function buildSightButtons()
|
||||
for i, name in SIGHTS do
|
||||
local b = Instance.new("TextButton")
|
||||
b.Size = UDim2.fromOffset(98, 56)
|
||||
b.LayoutOrder = i
|
||||
b.BackgroundColor3 = PANEL_LIGHT
|
||||
b.Font = FONT
|
||||
b.Text = name
|
||||
b.TextSize = 15
|
||||
b.TextColor3 = TEXT
|
||||
local corner = Instance.new("UICorner")
|
||||
corner.CornerRadius = UDim.new(0, 10)
|
||||
corner.Parent = b
|
||||
local stroke = Instance.new("UIStroke")
|
||||
stroke.Color = OUTLINE
|
||||
stroke.Thickness = 2
|
||||
stroke.Parent = b
|
||||
b.Parent = sightRow
|
||||
b.MouseButton1Click:Connect(function()
|
||||
chosenSight = name
|
||||
for _, other in sightButtons do
|
||||
other.BackgroundColor3 = PANEL_LIGHT
|
||||
other.TextColor3 = TEXT
|
||||
end
|
||||
b.BackgroundColor3 = ACCENT_DIM
|
||||
b.TextColor3 = ACCENT
|
||||
applyPreviewSight()
|
||||
end)
|
||||
sightButtons[name] = b
|
||||
end
|
||||
end
|
||||
|
||||
-- ---------------------------------------------------------------- play button
|
||||
local playBtn = Instance.new("TextButton")
|
||||
playBtn.AnchorPoint = Vector2.new(0.5, 1)
|
||||
playBtn.Position = UDim2.fromScale(0.5, 0.93)
|
||||
playBtn.Size = UDim2.fromOffset(360, 74)
|
||||
playBtn.BackgroundColor3 = ACCENT
|
||||
playBtn.Font = Enum.Font.GothamBlack
|
||||
playBtn.Text = "PLAY"
|
||||
playBtn.TextSize = 34
|
||||
playBtn.TextColor3 = DARK
|
||||
local playCorner = Instance.new("UICorner")
|
||||
playCorner.CornerRadius = UDim.new(0, 16)
|
||||
playCorner.Parent = playBtn
|
||||
local playStroke = Instance.new("UIStroke")
|
||||
playStroke.Color = OUTLINE
|
||||
playStroke.Thickness = 3
|
||||
playStroke.Parent = playBtn
|
||||
local playScale = Instance.new("UIScale")
|
||||
playScale.Parent = playBtn
|
||||
playBtn.Parent = gui
|
||||
playBtn.MouseEnter:Connect(function()
|
||||
TweenService:Create(playScale, TweenInfo.new(0.1), { Scale = 1.05 }):Play()
|
||||
end)
|
||||
playBtn.MouseLeave:Connect(function()
|
||||
TweenService:Create(playScale, TweenInfo.new(0.1), { Scale = 1 }):Play()
|
||||
end)
|
||||
playBtn.MouseButton1Click:Connect(function()
|
||||
-- hand the chosen sight to the server first (it survives on the player)
|
||||
sightRemote:FireServer(chosenSight)
|
||||
-- then ask the server to spawn us
|
||||
requestSpawn:FireServer()
|
||||
-- fade the menu away
|
||||
TweenService:Create(backdrop, TweenInfo.new(0.4), { BackgroundTransparency = 1 }):Play()
|
||||
TweenService:Create(modePanel, TweenInfo.new(0.4), { BackgroundTransparency = 1 }):Play()
|
||||
TweenService:Create(weaponPanel, TweenInfo.new(0.4), { BackgroundTransparency = 1 }):Play()
|
||||
TweenService:Create(title, TweenInfo.new(0.4), { TextTransparency = 1 }):Play()
|
||||
TweenService:Create(subtitle, TweenInfo.new(0.4), { TextTransparency = 1 }):Play()
|
||||
TweenService:Create(playBtn, TweenInfo.new(0.4), { BackgroundTransparency = 1 }):Play()
|
||||
task.delay(0.45, function()
|
||||
gui.Enabled = false
|
||||
end)
|
||||
end)
|
||||
|
||||
-- ---------------------------------------------------------------- build
|
||||
buildModeButtons()
|
||||
buildSightButtons()
|
||||
applyPreviewSight()
|
||||
modeButtons[chosenMode].BackgroundColor3 = ACCENT_DIM
|
||||
modeButtons[chosenMode]:FindFirstChild("Check").Visible = true
|
||||
sightButtons[chosenSight].BackgroundColor3 = ACCENT_DIM
|
||||
sightButtons[chosenSight].TextColor3 = ACCENT
|
||||
Reference in new issue
Block a user