How to enable/disable scripts after walking through a non collide part?

I have made 2 scripts in StarterPlayerScripts;
View1:
local Players = game:GetService(“Players”)
local RunService = game:GetService(“RunService”)

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

local CAMERA_DEPTH = 24
local HEIGHT_OFFSET = 2

local function updateCamera()
local character = player.Character
if character then
local root = character:FindFirstChild(“HumanoidRootPart”)
if root then
local rootPosition = root.Position + Vector3.new(0, 0, HEIGHT_OFFSET)
local cameraPosition = Vector3.new(rootPosition.X, rootPosition.Y, CAMERA_DEPTH)
camera.CFrame = CFrame.lookAt(cameraPosition, rootPosition)
end
end
end

RunService:BindToRenderStep(“SideScrollingCamera”, Enum.RenderPriority.Camera.Value + 1, updateCamera)

View2:
local Players = game:GetService(“Players”)
local RunService = game:GetService(“RunService”)

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

local CAMERA_DEPTH = 24
local HEIGHT_OFFSET = 2

local function updateCamera()
local character = player.Character
if character then
local root = character:FindFirstChild(“HumanoidRootPart”)
if root then
local rootPosition = root.Position + Vector3.new(0, 0, HEIGHT_OFFSET)
local cameraPosition = Vector3.new(rootPosition.X, rootPosition.Y, CAMERA_DEPTH)
camera.CFrame = CFrame.lookAt(cameraPosition, rootPosition)
end
end
end

RunService:BindToRenderStep(“SideScrollingCamera”, Enum.RenderPriority.Camera.Value + 1, updateCamera)

They both work fine when I enable them seperately, however I want to make it so that when a non colide part is walked through, they will toggle and/or switch between each other so the camera view will change from one side’s view to the other. I tried using chatgpt to help me do this since im not great at scripting but thothing I tried would work. Pls help me

1 Like
- View1 Script
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local switchPart = ReplicatedStorage:FindFirstChild("SwitchPart") or Instance.new("RemoteEvent")
switchPart.Name = "SwitchPart"
switchPart.Parent = ReplicatedStorage

local CAMERA_DEPTH = 24
local HEIGHT_OFFSET = 2

local function updateCamera()
    local character = player.Character
    if character then
        local root = character:FindFirstChild("HumanoidRootPart")
        if root then
            local rootPosition = root.Position + Vector3.new(0, 0, HEIGHT_OFFSET)
            local cameraPosition = Vector3.new(rootPosition.X, rootPosition.Y, CAMERA_DEPTH)
            camera.CFrame = CFrame.lookAt(cameraPosition, rootPosition)
        end
    end
end

switchPart.OnClientEvent:Connect(function()
    RunService:UnbindFromRenderStep("SideScrollingCamera")
    RunService:BindToRenderStep("SideScrollingCamera2", Enum.RenderPriority.Camera.Value + 1, updateCamera)
end)

RunService:BindToRenderStep("SideScrollingCamera", Enum.RenderPriority.Camera.Value + 1, updateCamera)
-- View2 Script
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local switchPart = ReplicatedStorage:FindFirstChild("SwitchPart") or Instance.new("RemoteEvent")
switchPart.Name = "SwitchPart"
switchPart.Parent = ReplicatedStorage

local CAMERA_DEPTH = 24
local HEIGHT_OFFSET = 2

local function updateCamera()
    local character = player.Character
    if character then
        local root = character:FindFirstChild("HumanoidRootPart")
        if root then
            local rootPosition = root.Position + Vector3.new(0, 0, HEIGHT_OFFSET)
            local cameraPosition = Vector3.new(rootPosition.X, rootPosition.Y, CAMERA_DEPTH)
            camera.CFrame = CFrame.lookAt(cameraPosition, rootPosition)
        end
    end
end

switchPart.OnClientEvent:Connect(function()
    RunService:UnbindFromRenderStep("SideScrollingCamera2")
    RunService:BindToRenderStep("SideScrollingCamera", Enum.RenderPriority.Camera.Value + 1, updateCamera)
end)

RunService:BindToRenderStep("SideScrollingCamera2", Enum.RenderPriority.Camera.Value + 1, updateCamera)

I added a RemoteEvent named “SwitchPart” to ReplicatedStorage. This RemoteEvent is used to signal the switch between the two camera views. Make sure to put a remote event named “SwitchPart” in replicated storage and that these two scripts are a local script in StarterPlayerScripts.

ok but how do I make them switch based on when the player touches the non colide part called lets say “Part1” for example?

Quick google search:
BasePart.Touched event

ok I have read the page and im still confused

ok so I made a seperate script to activate it under a part:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SPart1 = script.Parent
    
   -- RemoteEvent for camera switching
   local switchPart = ReplicatedStorage:WaitForChild("SwitchPart")

    -- Function to handle player touches
local function onTouch(hit)
	print("Touched!")
	local character = hit.Parent
  local humanoid = character and character:FindFirstChild("Humanoid")

	    if humanoid and humanoid:IsA("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(character)
		if player then
			-- Signal the SwitchPart RemoteEvent for the specific player
			print("Player found:", player.Name)
			switchPart:FireClient(player)
		end
	   end
      end

    -- Connect the onTouch function to the Touched event of SPart1
    SPart1.Touched:Connect(onTouch)

It works fine in terms of activating the SwitchPart Remote Event. However I am still stuck on trying to get it to actually work. in View2 I put a println statement in so that I could tell where in the script the code is having issues at. However It prints the statement out just fine, However it just doesnt want to change views. Pls help, Im stuck.