Camera not reverting back to players camera when exit is pressed

Hi there!

Currently, I’ve been developing a sort of gun “buying” system except without the buying part and just pressing the button to get the gun.

The whole point is so that a player can use the proximity prompt to “talk” to the NPC, have the camera focus on the NPC and select and gun then press Exit.

Currently, the code when pressing the Exit button (BackButton) is not closing, merely closing the Gui and not reverting back to the player’s camera.

Here are the codes (there are no errors)

Camera Mover/ NPC Focuser Code:

local CurrentCamera = workspace.CurrentCamera
local TweenService = game:GetService("TweenService")
local runService = game:GetService("RunService")

local Prompt = game.Workspace.NPCRSIX.ProximityPrompt
local BackButton = game.StarterGui.ScreenGui.BackButton

CurrentCamera.CameraType = Enum.CameraType.Scriptable

local Animation = TweenService:Create(CurrentCamera, TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.InOut, 0, false, 0), {["CFrame"] = workspace.REODPART.CFrame})

TEST = false

Prompt.Triggered:Connect(function(player)
	task.wait(0.1)
	Prompt.Enabled = false
	Animation:Play()
	CurrentCamera.HeadLocked = false
    CurrentCamera.CameraType = Enum.CameraType.Fixed
	player.Character:WaitForChild("HumanoidRootPart").Anchored = true
	Animation.Completed:Wait()
	runService:BindToRenderStep("NPCfocus", Enum.RenderPriority.Camera.Value + 1, function()
		CurrentCamera.CFrame = CFrame.new(workspace.REODPART.Position, game:GetService("Workspace").FOCUSPART.Position)
		end)
BackButton.MouseButton1Click:Connect(function(player)
	runService:UnbindFromRenderStep("NPCfocus")
	player.Character:WaitForChild("HumanoidRootPart").Anchored = false
		Animation:Stop()
		Prompt.Enabled = true
		CurrentCamera.HeadLocked = true
		CurrentCamera.CameraType = Enum.CameraType.Scriptable
end)
end)

Gui Code:

local Prompt = game.Workspace.NPCRSIX.ProximityPrompt
local ScreenGui = game.Players.LocalPlayer.PlayerGui.ScreenGui
local Button = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton
local BackButton = game.Players.LocalPlayer.PlayerGui.ScreenGui.BackButton

Prompt.Triggered:Connect(function()
	ScreenGui.Enabled = true
end)

Button.MouseButton1Click:Connect(function()
	local plr = game.Players.LocalPlayer
	local backpack = plr:WaitForChild('Backpack')
	local Shotgun = game:GetService('ReplicatedStorage'):WaitForChild('Shotgun')
	Shotgun:Clone().Parent = backpack
end)

BackButton.MouseButton1Click:Connect(function()
	ScreenGui.Enabled = false
end)

I think I may need to add a piece to the Gui code so that it talks to the NPC code and verifies that the player is closing the “shop”.
I’ve tried putting the subject back to the humanoid but I am not fully sure I did it correctly.

Any help would be much appreciated as these are issues I am not sure how to solve.

Check comments for updated Gui/NPC codes

Does it work if you set the CameraSubject to the player’s character?

Hmm no it does not work, I’ve also tried removing the other values to try to cancel it out but that doesnt work either;

Hmm… What about if the CameraSubject is the Humanoid? Does it stay where it was before?

Yes but I think its because of my phrasing

CurrentCamera.CameraSubject = player.Humanoid

I also did the two-sided communication and it’s just mainly the camera subject, I can’t get it to remove the other subject without making it just a one-time thing.

local CurrentCamera = workspace.CurrentCamera
local TweenService = game:GetService("TweenService")
local runService = game:GetService("RunService")

local Prompt = game.Workspace.NPCRSIX.ProximityPrompt
local BackButton = game.StarterGui.ScreenGui.BackButton

CurrentCamera.CameraType = Enum.CameraType.Scriptable

local Animation = TweenService:Create(CurrentCamera, TweenInfo.new(1, Enum.EasingStyle.Exponential, Enum.EasingDirection.InOut, 0, false, 0), {["CFrame"] = workspace.REODPART.CFrame})

TEST = false

Prompt.Triggered:Connect(function(player)
	task.wait(0.1)
	Prompt.Enabled = false
	Animation:Play()
  CurrentCamera.HeadLocked = false
   CurrentCamera.CameraType = Enum.CameraType.Scriptable
	player.Character:WaitForChild("HumanoidRootPart").Anchored = true
	Animation.Completed:Wait()
	runService:BindToRenderStep("NPCfocus",Enum.RenderPriority.Camera.Value + 1, function(player)
		CurrentCamera.CFrame = CFrame.new(workspace.REODPART.Position, game:GetService("Workspace").FOCUSPART.Position)
	end)
	BackButton.MouseButton1Click:Connect(function(player)
		Prompt.Enabled = true
		CurrentCamera.HeadLocked = true
		Animation:Stop()
	runService:UnbindFromRenderStep("NPCfocus")
		player.Character:WaitForChild("HumanoidRootPart").Anchored = false
		CurrentCamera.CameraSubject = player.Character.Humanoid
	end)
end)
local Prompt = game.Workspace.NPCRSIX.ProximityPrompt
local ScreenGui = game.Players.LocalPlayer.PlayerGui.ScreenGui
local Button = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton
local BackButton = game.Players.LocalPlayer.PlayerGui.ScreenGui.BackButton
local CurrentCamera = workspace.CurrentCamera

local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()

Prompt.Triggered:Connect(function()
	ScreenGui.Enabled = true
end)

Button.MouseButton1Click:Connect(function()
	local plr = game.Players.LocalPlayer
	local backpack = plr:WaitForChild('Backpack')
	local Shotgun = game:GetService('ReplicatedStorage'):WaitForChild('Shotgun')
	Shotgun:Clone().Parent = backpack
end)

BackButton.MouseButton1Click:Connect(function()
	ScreenGui.Enabled = false
	CurrentCamera.CameraType = Enum.CameraType.Fixed
	
end)

Seriously I need help