I’ve recently been struggling and trying to find an answer to this very weird issue.
When players join the game, their camera is set to a part called “MenuCamera” in the workspace. This is a camera that displays a backdrop of the game preview.
Desired functionality: When the textbutton called “Button” under the frame “Spawn” is clicked, it should make the UI invisible as well as set the player’s camera back to the default around the player.
Issue is, it does make the UI invisible but the Camera is not set back properly.
Any help would be greatly appreciated.
Attached below, the LocalScript located within the GUI itself, controlling the changes for both the UI and the local player’s character.
local RS = game:GetService("ReplicatedStorage")
local events = RS.Events
local ui = script.Parent
local menu = ui.Menu
local camera = game.Workspace.Camera
local part = game.Workspace:WaitForChild("MenuCamera")
local music = ui.Music
local plr = game.Players.LocalPlayer
local char = plr.Character
local function enable()
ui.Enabled = true
repeat camera.CameraType = Enum.CameraType.Scriptable wait() until camera.CameraType == Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
music:Play()
char:WaitForChild("HumanoidRootPart").Anchored = true
end
local function disable()
ui.Enabled = false
music:Stop()
char:WaitForChild("HumanoidRootPart").Anchored = false
end
menu.Spawn.Button.Activated:Connect(function()
camera.CameraType = Enum.CameraType.Custom
camera.CameraSubject = char:WaitForChild("Humanoid")
disable()
end)
menu.Drive.Button.Activated:Connect(function()
menu.BackgroundTransparency = 1
menu.Drive.Visible = false
menu.Spawn.Visible = false
menu.Title.Visible = false
menu.Depot.Visible = true
menu.Settings.Visible = false
--menu.Credits.Visible = false
end)
menu.Depot.Exit.Button.Activated:Connect(function()
menu.Depot.Visible = false
menu.Train.Visible = false
menu.BackgroundTransparency = 0
menu.Spawn.Visible = true
menu.Title.Visible = true
menu.Settings.Visible = true
menu.Drive.Visible = true
--menu.Credits.Visible = true
end)
for i, v in pairs(menu.Depot:GetChildren()) do
if v.ClassName == "ImageLabel" and v.Name ~= "Exit" then
v.Button.Activated:Connect(function()
menu.Train.Visible = true
menu.Depot.Selected.Value = v.Name
v.ImageColor3 = Color3.new(.6,.1,.1)
repeat task.wait(0.1) until
menu.Depot.Selected.Value ~= v.Name
v.ImageColor3 = Color3.new(0,0,0)
end)
end
end
for i, v in pairs(menu.Train:GetChildren()) do
if v.ClassName == "ImageLabel" and v.Name ~= "Confirm" then
v.Button.Activated:Connect(function()
menu.Train.Selected.Value = v.Name
v.ImageColor3 = Color3.new(.6,.1,.1)
repeat task.wait(0.1) until
menu.Train.Selected.Value ~= v.Name
v.ImageColor3 = Color3.new(0,0,0)
end)
end
end
menu.Train.Confirm.Button.Activated:Connect(function()
local yard = menu.Depot.Selected.Value --needs to be equal to a model.Name with the same string located in the Yards folder of the Signalling Folder in the workspace
local train = menu.Train.Selected.Value --needs to be equal to a model.Name with the same string located in the Trains folder of RepStor
local route = "M01" ----will be based on newer UI choices later. M01 is the code for the first route
if yard == "" or train == "" or route == "" then
error("Player did not select one of the settings!")
else
print(yard)
game.ReplicatedStorage.Events.SpawnTrain:FireServer(char, yard, train, route)
disable()
end
end)
game.ReplicatedStorage.Events.SpawnTrain.OnClientEvent:Connect(function(msg)
menu.Train.Confirm.Button.Text = msg
enable()
end)
local SignalMeanings = true
menu.Settings.Button.Activated:Connect(function()
menu.BackgroundTransparency = 1
menu.Drive.Visible = false
menu.Spawn.Visible = false
menu.Title.Visible = false
menu.Depot.Visible = false
menu.Settings.Visible = false
menu.SettingsUI.Visible = true
--menu.Credits.Visible = false
if SignalMeanings == false then
menu.SettingsUI.SignalMeanings.ImageColor3 = Color3.new(0.6, 0, 0)
elseif SignalMeanings == true then
menu.SettingsUI.SignalMeanings.ImageColor3 = Color3.new(0, 0.8, 0)
end
end)
menu.SettingsUI.SignalMeanings.Button.Activated:Connect(function()
if SignalMeanings == false then
menu.SettingsUI.SignalMeanings.ImageColor3 = Color3.new(0, 0.8, 0)
for _, v in pairs(workspace.Signalling:GetChildren()) do
if v:IsA("Model") then
v.Signal.simple.ui.Enabled = true
end
end
SignalMeanings = true
elseif SignalMeanings == true then
menu.SettingsUI.SignalMeanings.ImageColor3 = Color3.new(0.6, 0, 0)
for _, v in pairs(workspace.Signalling:GetChildren()) do
if v:IsA("Model") then
v.Signal.simple.ui.Enabled = false
end
end
SignalMeanings = false
end
end)
menu.SettingsUI.Exit.Button.Activated:Connect(function()
menu.Depot.Visible = false
menu.Train.Visible = false
menu.SettingsUI.Visible = false
menu.BackgroundTransparency = 0
menu.Spawn.Visible = true
menu.Title.Visible = true
menu.Settings.Visible = true
menu.Drive.Visible = true
--menu.Credits.Visible = true
end)
enable()