Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I go about fixing my CameraSubject not switching?

LocalScript inside StarterPlayerScripts I am basically making a script where you go into a magnitude of a block, a gui pops up you click e and then more guis pop up. From there you can then naviage left or right (what Im trying to do) but there seems to be an issue with it( On my second stepped) I have it print my characters name for the first time I prompt it to, but not the second, which is very startling because of everything appearing to meet my conditions.

(long script)

error would appear to be under "-- // Manuvering through the shop \\ --" at the very bottom

-- Made By AltNature
-- What we want to do -- [ 1. When you enter the brick , bring up the gui ] 
--[[ "Press E to open shop" , Player clicks "E" Then transitions into custom camera mode like Mining simulator
	to choose your weapon. ]]--
-- //  Variables \\ --
local f = game.Workspace.CameraParts
local debounce = false
local check = true
local player = game.Players.LocalPlayer
local pressE = game.Players.LocalPlayer.PlayerGui:WaitForChild("gunShopGUI"):WaitForChild("pressE")
local pressEadd = game.Players.LocalPlayer.PlayerGui:WaitForChild("gunShopGUI"):WaitForChild("pressEadd")
local userInput = game:GetService("UserInputService")
local humanoid = player.Character.Humanoid
local s =  player.PlayerGui:WaitForChild("gunShopGUI")
local sl = s.Lefts
local sr = s.Rights
local cameras = {f.Revolver, 
	f.G36C,
	f.GoldRevolver,
	f.USP,
	f.HK417,
	f.FP6,
	f.MG4,
    f.AWM_F}

local lefts = {sl.Left,
	sl.LeftBottom,
	sl.LeftTop,
	sl.LeftLeft,
    sl.LeftRight}

local rights = {sr.Right,
	sr.RightBottom,
	sr.RightTop,
	sr.RightLeft,
    sr.RightRight}

local exit = s.Exit

local Camera = workspace.Camera

-- // Camera Functions \\ --

function cameraMode()
	local target
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CameraSubject = target
	wait()
	local target = cameras[1]
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = target.CFrame
end

function cameraModetwo()
	local target
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CameraSubject = target
	wait()
	local target = cameras[2]
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = target.CFrame
end

function cameraModethree()
	local target
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CameraSubject = target
	wait()
	local target = cameras[3]
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = target.CFrame
end

function cameraModefour()
	local target
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CameraSubject = target
	wait()
	local target = cameras[4]
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = target.CFrame
end

function cameraModefive()
	local target
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CameraSubject = target
	wait()
	local target = cameras[5]
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = target.CFrame
end

function cameraModesix()
	local target
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CameraSubject = target
	wait()
	local target = cameras[6]
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = target.CFrame
end

function cameraModeseven()
	local target
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CameraSubject = target
	wait()
	local target = cameras[7]
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = target.CFrame
end

function cameraModeEight()
	local target
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CameraSubject = target
	wait()
	local target = cameras[8]
	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = target.CFrame
end

function exitCameraMode()
	    Camera.CameraType = Enum.CameraType.Custom
        Camera.CameraSubject = player.Character.Humanoid
        Camera.CFrame = player.Character.Head.CFrame
        player.Character.Humanoid.WalkSpeed = 16
end

-- // =================== \\ --

function visibleRightandLeftandExit()
	 for i, v in pairs(lefts) do
		v.Visible = true
	       end
	       for i, v in pairs(rights) do
		 v.Visible = true
      end
	exit.Visible = true
end

function invisibleRightandLeftandExit()
	 for i, v in pairs(lefts) do
		v.Visible = false
	       end
	       for i, v in pairs(rights) do
		 v.Visible = false
      end
	exit.Visible = false
end


function input()
	userInput.InputBegan:Connect(function(input, gp)        -- If they click "E" , then cameraMode()
	if input.KeyCode == Enum.KeyCode.E then
		if not gp then
			cameraMode()
			visibleRightandLeftandExit()
			player.Character.Humanoid.WalkSpeed = 0
			pressE.Parent = game:GetService("ServerStorage")
			pressEadd.Parent = game:GetService("ServerStorage")
		end
	 end
   end) 
end
-- // The Activation \\ --



game:GetService("RunService").RenderStepped:Connect(function()
 if (player.Character.HumanoidRootPart.Position - workspace.Part.Position).Magnitude <= 11 then
	pressE.Visible = true
	pressEadd.Visible = true
	input()
	print("Rendering")
elseif (player.Character.HumanoidRootPart.Position - workspace.Part.Position).Magnitude > 11 then
	pressE.Visible = false
	pressEadd.Visible = false
	print("Rendering")
  end
end) 

                                                
humanoid.Died:Connect(function()
	    exitCameraMode()
	if Camera.CameraType == Enum.CameraType.Custom then
	   wait(5)
	   pressE.Parent = s
	   pressEadd.Parent = s
	   player.Character.Humanoid.WalkSpeed = 16
	   invisibleRightandLeftandExit()
	end
end)

-- // Manuvering through the GUI shop \\ --
 
if Camera.CameraSubject ~= player.Character.Humanoid and rights[1].Visible == true then
		lefts[1].MouseButton1Click:Connect(function()
			if Camera.CameraSubject ~= cameras[1] then
				if Camera.CameraSubject == cameras[2] then
					cameraMode()
				end
				if Camera.CameraSubject == cameras[3] then
					cameraModetwo()
				end
				if Camera.CameraSubject == cameras[4] then
					cameraModethree()
				end
				if Camera.CameraSubject == cameras[5] then
					cameraModefour()
				end
				if Camera.CameraSubject == cameras[6] then
					cameraModefive()
				end
				if Camera.CameraSubject == cameras[7] then
					cameraModesix()
				end
				if Camera.CameraSubject == cameras[8] then
					cameraModeseven()
				end
			end
		end)
		rights[1].MouseButton1Click:Connect(function()
			if Camera.CameraSubject ~= cameras[8] then
				if Camera.CameraSubject == cameras[1] then
					cameraModetwo()
					print("Maybe by chance? "")
				end
				if Camera.CameraSubject == cameras[2] then
					cameraModethree()
				end
				if Camera.CameraSubject == cameras[3] then
					cameraModefour()
				end
				if Camera.CameraSubject == cameras[4] then
					cameraModefive()
				end
				if Camera.CameraSubject == cameras[5] then
					cameraModesix()
				end
				if Camera.CameraSubject == cameras[6] then
					cameraModeseven()
				end
				if Camera.CameraSubject == cameras[7] then
					cameraModeEight()
				end
			 end
		end)
	end
	exit.MouseButton1Click:Connect(function()
		exitCameraMode()
		
	end)

3 comments

1

Too much code. Can you try and crop it down to where the problem might be occurring if possible?

0

^ Up vote

0

Next time, just post the part of the script where you are having the problems.

2 answers

I had this same problem a while back and I fixed it very simply using a script like this:

local character = game.Players.LocalPlayer.Character
		
if character then
	local camera = workspace.CurrentCamera
	camera.CameraType = Enum.CameraType.Custom
	camera.CameraSubject = character:FindFirstChild("Humanoid")
end

3 comments

0

nope. i got the answer i will post it in answers

0

why would I upvote you are wrong

0

OK. It's not an incorrect answer. It may just be incorrect for your script. And I didn't ask for an upvote

-- Made By AltNature
-- What we want to do -- [ 1. When you enter the brick , bring up the gui ] 
--[[ "Press E to open shop" , Player clicks "E" Then transitions into custom camera mode like Mining simulator
	to choose your weapon. ]]--
-- //  Variables \\ --
local f = game.Workspace.CameraParts
local debounce = false
local check = true
local player = game.Players.LocalPlayer
local pressE = game.Players.LocalPlayer.PlayerGui:WaitForChild("gunShopGUI"):WaitForChild("pressE")
local pressEadd = game.Players.LocalPlayer.PlayerGui:WaitForChild("gunShopGUI"):WaitForChild("pressEadd")
local userInput = game:GetService("UserInputService")
local humanoid = player.Character:WaitForChild("Humanoid")
local s =  player.PlayerGui:WaitForChild("gunShopGUI")
local purchase = s.Purchase
local amount = player.PlayerGui:WaitForChild("gunShopGUI"):WaitForChild("AmountNeeded")
amount.Visible = false
local sl = s.Lefts
local sr = s.Rights
local cameras = {f.Revolver, 
	f.G36C,
	f.GoldRevolver,
	f.USP,
	f.HK417,
	f.FP6,
	f.MG4,
    f.AWM_F}

local lefts = {sl.Left,
	sl.LeftBottom,
	sl.LeftTop,
	sl.LeftLeft,
    sl.LeftRight}

local rights = {sr.Right,
	sr.RightBottom,
	sr.RightTop,
	sr.RightLeft,
    sr.RightRight}

local assets = {"rbxassetid://3348525523",
	"rbxassetid://3348526597",
	"rbxassetid://3348526597",
	"rbxassetid://3348530535",
	"rbxassetid://3348531577",
	"rbxassetid://3348531577",
	"rbxassetid://3348532463"}

local exit = s.Exit

local Camera = workspace.Camera

-- // Camera Functions \\ --

function cameraMode()
	    local target = cameras[1]
    Camera.CameraSubject = target
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = target.CFrame
end

function cameraModetwo()
    local target = cameras[2]
    Camera.CameraSubject = target
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = target.CFrame
end

function cameraModethree()
    local target = cameras[3]
    Camera.CameraSubject = target
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = target.CFrame
end

function cameraModefour()
    local target = cameras[4]
    Camera.CameraSubject = target
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = target.CFrame
end

function cameraModefive()
    local target = cameras[5]
    Camera.CameraSubject = target
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = target.CFrame
end

function cameraModesix()
    local target = cameras[6]
    Camera.CameraSubject = target
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = target.CFrame
end

function cameraModeseven()
    local target = cameras[7]
    Camera.CameraSubject = target
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = target.CFrame
end

function cameraModeEight()
    local target = cameras[8]
    Camera.CameraSubject = target
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = target.CFrame
end

function exitCameraMode()
	    Camera.CameraType = Enum.CameraType.Custom
        Camera.CameraSubject = player.Character.Humanoid
        Camera.CFrame = player.Character.Head.CFrame
        player.Character.Humanoid.WalkSpeed = 16
end

-- // =================== \\ --

function visibleRightandLeftandExitPurchase()
	 for i, v in pairs(lefts) do
		v.Visible = true
	       end
	       for i, v in pairs(rights) do
		 v.Visible = true
      end
	exit.Visible = true
	purchase.Visible = true
	amount.Visible = true
end

function invisibleRightandLeftandExitPurchase()
	 for i, v in pairs(lefts) do
		v.Visible = false
	       end
	       for i, v in pairs(rights) do
		 v.Visible = false
      end
	exit.Visible = false
	purchase.Visible = false
	amount.Visible = false
end


function input()
	userInput.InputBegan:Connect(function(input, gp)        -- If they click "E" , then cameraMode()
	if input.KeyCode == Enum.KeyCode.E then
		if not gp then
			cameraMode()
			visibleRightandLeftandExitPurchase()
			player.Character.Humanoid.WalkSpeed = 0
			pressE.Parent = game:GetService("ServerStorage")
			pressEadd.Parent = game:GetService("ServerStorage")
		end
	 end
   end) 
end
-- // The Activation \\ --



game:GetService("RunService").RenderStepped:Connect(function()
 if amount.Visible == true then
	print("Okay")
if Camera.CameraSubject == cameras[2] then
	wait()
	amount.Image = assets[1]
if Camera.CameraSubject == cameras[3] then
	wait()
	amount.Image = assets[2]
if Camera.CameraSubject == cameras[4] then
	wait()
	amount.Image = assets[3]
if Camera.CameraSubject == cameras[5] then
	wait()
	amount.Image = assets[4]
if Camera.CameraSubject == cameras[6] then
	wait()
	amount.Image = assets[5]
if Camera.CameraSubject == cameras[7] then
	wait()
	amount.Image = assets[6]
if Camera.CameraSubject == cameras[8] then
	wait()
	amount.Image = assets[7]
 end
end
end
end
end
end
end
end
if (player.Character.HumanoidRootPart.Position - workspace.Part.Position).Magnitude <= 11 then
	pressE.Visible = true
	pressEadd.Visible = true
	input()
	print("Rendering")
elseif (player.Character.HumanoidRootPart.Position - workspace.Part.Position).Magnitude > 11 then
	pressE.Visible = false
	pressEadd.Visible = false
	print("Rendering")
  end
end) 

                                                
humanoid.Died:Connect(function()
	    exitCameraMode()
	if Camera.CameraType == Enum.CameraType.Custom then
	   wait(5)
	   pressE.Parent = s
	   pressEadd.Parent = s
	   player.Character.Humanoid.WalkSpeed = 16
	   invisibleRightandLeftandExitPurchase()
	end
end)

-- // Manuvering through the GUI shop \\ --
 

lefts[1].MouseButton1Click:Connect(function()
		if Camera.CameraSubject == cameras[2] then
		    cameraMode()
		elseif Camera.CameraSubject == cameras[3] then
			cameraModetwo()
		
		elseif Camera.CameraSubject == cameras[4] then
			cameraModethree()
	    
		elseif Camera.CameraSubject == cameras[5] then
			cameraModefour()
		
		elseif Camera.CameraSubject == cameras[6] then
			cameraModefive()
		
		elseif Camera.CameraSubject == cameras[7] then
			cameraModesix()
		
		elseif Camera.CameraSubject == cameras[8] then
			cameraModeseven()
	end
end)


rights[1].MouseButton1Click:Connect(function()
		if Camera.CameraSubject == cameras[1] then
		cameraModetwo()
		elseif Camera.CameraSubject == cameras[2] then
			cameraModethree()
		
		elseif Camera.CameraSubject == cameras[3] then
			cameraModefour()
	    
		elseif Camera.CameraSubject == cameras[4] then
			cameraModefive()
		
		elseif Camera.CameraSubject == cameras[5] then
			cameraModesix()
		
		elseif Camera.CameraSubject == cameras[6] then
			cameraModeseven()
		
		elseif Camera.CameraSubject == cameras[7] then
			cameraModeEight()
	end
end)

exit.MouseButton1Click:Connect(function()
	exitCameraMode()
	invisibleRightandLeftandExitPurchase()
	 pressE.Parent = s
	   pressEadd.Parent = s
	   player.Character.Humanoid.WalkSpeed = 16
end)

purchase.MouseButton1Click:Connect(function()
	
end)











This discussion is preserved as it was. New answers, comments, and votes are closed.