Problem: Camera doesn’t reset correctly when the GameEvent
message is StartGame
.
Info: When GameEven
message is EndGame
the map gets destroyed and the players fall into the void Killing them, but the camera changes to the CameraPart
before they die. When the player joins the game and plays one round everything is fine but when GameEven
message is StartGame
again, the camera goes back to the player but the camera does not move at all.
Code:
local Player = game.Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local CameraPart = game.Workspace.Lobby:WaitForChild("CameraPart")
local GameEvent = game.ReplicatedStorage.RemoteEvents.GameEvent
-- Store original camera settings
local originalCameraType = Camera.CameraType
local originalCameraCFrame = Camera.CFrame
-- Set initial camera to the lobby camera part
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CameraPart.CFrame
GameEvent.OnClientEvent:Connect(function(Message)
if Message == "EndGame" then
task.wait(2)
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CameraPart.CFrame
elseif Message == "StartGame" then
Camera.CameraType = originalCameraType
Camera.CFrame = originalCameraCFrame
end
end)