Hello! So I made a game menu screen with a play button for my game. When players join the game, they see a camera panning around the map and a simple play button. When they click the play button, it immediately brings them to their regular character view. But when I test out the game and reset or die, it goes back to panning with the play button disappearing. I’ve been trying to make the menu screen only appear when a play first joins, but none of the scripts I’ve tried have worked. Do any of you know what the issue might be? My script for the game menu is shown below.
-- LocalScript inside the LoadingScreenGui
local button = script.Parent:WaitForChild("ImageButton")
local camera = workspace.CurrentCamera
local runService = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
-- Define the panning parameters
local panSpeed = 0.05
local panDistance = 20
local randomPoint = Vector3.new(math.random(-100, 100), 10, math.random(-100, 100)) -- Adjust the range as needed
-- Variables to capture the initial camera state
local isPanning = true
-- Function to pan the camera around the random point
local function panCamera()
if isPanning then
local time = tick()
local offset = Vector3.new(math.sin(time * panSpeed) * panDistance, 10, math.cos(time * panSpeed) * panDistance)
camera.CFrame = CFrame.new(randomPoint + offset, randomPoint)
end
end
-- Connect the function to the render step
runService.RenderStepped:Connect(panCamera)
-- Disable player controls using PlatformStand
local function disableControls()
local humanoid = player.Character and player.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid.PlatformStand = true
end
end
-- Enable player controls
local function enableControls()
local humanoid = player.Character and player.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid.PlatformStand = false
end
end
-- Handle the play button click
button.MouseButton1Click:Connect(function()
-- Play the click sound
local clickSound = script.Parent.Parent:FindFirstChild("ClickSound")
if clickSound then
clickSound:Play()
end
-- Stop panning and disable player controls
isPanning = false
disableControls()
-- Reset the camera to the character's original view
local character = player.Character
local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
camera.CFrame = CFrame.new(humanoidRootPart.Position + Vector3.new(0, 5, 10), humanoidRootPart.Position) -- Adjust as needed
end
-- Enable controls and hide the loading screen immediately
enableControls()
script.Parent.Enabled = false
end)
-- Hide the loading screen when the player joins the game
local function onPlayerAdded(player)
script.Parent.Enabled = false
end
-- Connect the function to the player added event
players.PlayerAdded:Connect(onPlayerAdded)
And here is the script I’ve tried for disabling the menu when a player resets/dies
-- LocalScript inside the LoadingScreenGui
local button = script.Parent:WaitForChild("ImageButton")
local camera = workspace.CurrentCamera
local runService = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local replicatedStorage = game:GetService("ReplicatedStorage")
local loadingScreenEvent = replicatedStorage:WaitForChild("LoadingScreenEvent")
-- Define the panning parameters
local panSpeed = 0.05
local panDistance = 20
local centralPoint = Vector3.new(-125.28, 586.85, -362.38)
local pitchAngle = math.rad(-45) -- Negative angle to look down
-- Variables to capture the initial camera state
local isPanning = false
-- Function to pan the camera around the central point
local function panCamera()
if isPanning then
local time = tick()
local offset = Vector3.new(math.sin(time * panSpeed) * panDistance, 0, math.cos(time * panSpeed) * panDistance)
local cameraPosition = centralPoint + offset
local cameraCFrame = CFrame.new(cameraPosition, centralPoint) * CFrame.Angles(pitchAngle, 0, 0)
camera.CFrame = cameraCFrame
end
end
-- Connect the function to the render step
runService.RenderStepped:Connect(panCamera)
-- Handle the play button click
button.MouseButton1Click:Connect(function()
-- Play the click sound
local clickSound = script.Parent.Parent:FindFirstChild("ClickSound")
if clickSound then
clickSound:Play()
end
-- Stop panning and hide the loading screen
isPanning = false
script.Parent.Enabled = false
-- Reset the camera to the character's original view
local character = player.Character
local humanoidRootPart = character and character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
camera.CFrame = CFrame.new(humanoidRootPart.Position + Vector3.new(0, 5, 10), humanoidRootPart.Position) -- Adjust as needed
end
-- Enable player controls
local humanoid = character and character:FindFirstChild("Humanoid")
if humanoid then
humanoid.PlatformStand = false
end
end)
-- Hide the loading screen and stop panning when the player joins the game
local function onPlayerAdded(newPlayer)
if newPlayer == player then
script.Parent.Enabled = false
isPanning = false
end
end
-- Connect the function to the player added event
players.PlayerAdded:Connect(onPlayerAdded)
-- loading screen and panning stop when the player respawns or resets
player.CharacterAdded:Connect(function()
isPanning = false
script.Parent.Enabled = false
end)
player.CharacterRemoving:Connect(function()
isPanning = false
script.Parent.Enabled = false
end)