Basically, when I die, the camera will get stuck on the camera part and you cannot fix it. I want to make it so when you join in, the camera will get set but then when you respawn it will not.
Current code:
local mouse = game.Players.LocalPlayer:GetMouse()
local cam = workspace.CurrentCamera
local startergui = game:GetService("StarterGui")
local camParts = {}
local menuCam
local playerScripts = game:GetService("Players").LocalPlayer:WaitForChild("PlayerScripts")
local Satchel = require(playerScripts:WaitForChild("Satchel"):WaitForChild("Satchel"))
Satchel:SetBackpackEnabled(false)
startergui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
local function waitForMenuCam()
menuCam = workspace:WaitForChild("Map"):WaitForChild("MenuCam")
while not menuCam do
task.wait(1)
menuCam = workspace:FindFirstChild("Map"):FindFirstChild("MenuCam")
end
end
waitForMenuCam()
if menuCam then
pos1 = menuCam:WaitForChild("pos1")
pos2 = menuCam:WaitForChild("pos2")
table.insert(camParts, pos1)
table.insert(camParts, pos2)
end
local Scale = 5000
local cameraActive = false
local currentIndex = 1
cam.CameraType = Enum.CameraType.Scriptable
local function updateCamera()
if cameraActive and #camParts > 0 then
local camPart = camParts[currentIndex]
if camPart then
local center = Vector2.new(cam.ViewportSize.X / 2, cam.ViewportSize.Y / 2)
local x = mouse.X - center.X / 2
local y = mouse.Y - center.Y / 2
local xOffset = x / Scale
local yOffset = y / Scale
local lookAtPoint = camPart.Position + camPart.CFrame.LookVector * 5
local vector = Vector3.new(
lookAtPoint.X - xOffset,
lookAtPoint.Y - yOffset,
lookAtPoint.Z - xOffset)
local result = CFrame.lookAt(camPart.Position, vector)
cam.CFrame = result
end
end
end
local renderSteppedConnection
local function startCameraUpdate()
if not renderSteppedConnection then
renderSteppedConnection = game:GetService("RunService").RenderStepped:Connect(updateCamera)
end
end
local function stopCameraUpdate()
if renderSteppedConnection then
renderSteppedConnection:Disconnect()
renderSteppedConnection = nil
end
end
local bindable = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("MenuOff")
bindable.Event:Connect(function(toggle)
Satchel:SetBackpackEnabled(true)
startergui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
cameraActive = false
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = game:GetService("Players").LocalPlayer.Character.Humanoid
stopCameraUpdate()
end)
local function updateCameraPart()
if cameraActive and #camParts > 0 then
local newFrame = Instance.new("Frame")
newFrame.Name = "Transition"
newFrame.Size = UDim2.new(1, 0, 1, 0)
newFrame.BackgroundColor3 = Color3.new(0, 0, 0)
newFrame.BackgroundTransparency = 1
newFrame.Visible = true
local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local modernGui = playerGui:FindFirstChild("Menu")
newFrame.Parent = modernGui
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local fadeInTween = tweenService:Create(newFrame, tweenInfo, {BackgroundTransparency = 0})
local fadeOutTween = tweenService:Create(newFrame, tweenInfo, {BackgroundTransparency = 1})
fadeInTween:Play()
fadeInTween.Completed:Connect(function()
currentIndex = (currentIndex % #camParts) + 1
local camPart = camParts[currentIndex]
if camPart then
cam.CFrame = CFrame.lookAt(camPart.Position, camPart.Position + camPart.CFrame.LookVector * 5)
end
fadeOutTween:Play()
fadeOutTween.Completed:Connect(function()
newFrame:Destroy()
task.wait(math.random(5, 7))
updateCameraPart()
end)
end)
end
end
local function onPlayerAdded(player)
if player == game.Players.LocalPlayer then
cameraActive = true
startCameraUpdate()
updateCameraPart()
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
if game.Players.LocalPlayer then
onPlayerAdded(game.Players.LocalPlayer)
end
game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
cameraActive = false
cam.CameraType = Enum.CameraType.Custom
cam.CameraSubject = game:GetService("Players").LocalPlayer.Character.Humanoid
stopCameraUpdate()
end)
Thanks