Hello! I need a hand; when I press the “E” keycode, nothing happens. What is wrong? I’ve tried multiple ways, and nothing seems to work.
Module Script (replicatedstorage):
-- CameraModuleScript
local CameraModule = {}
function CameraModule.setupCamera(character, camera, forwardOffset, upwardOffset)
local head = character:WaitForChild("Head")
local function updateCameraPosition()
local offset = Vector3.new(0, upwardOffset, forwardOffset)
camera.CFrame = CFrame.new(head.Position + offset)
end
-- Set the initial camera position
updateCameraPosition()
-- Continuously update the camera position to follow the head
head:GetPropertyChangedSignal("Position"):Connect(updateCameraPosition)
local isThirdPerson = false
local function toggleCameraView()
isThirdPerson = not isThirdPerson
if isThirdPerson then
-- Change to third-person view
camera.CameraType = Enum.CameraType.Scriptable
else
-- Change back to first-person view
camera.CameraType = Enum.CameraType.Custom
end
end
local function setupInput()
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
-- Bind the toggle function to the "E" key using KeyDown
mouse.KeyDown:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
toggleCameraView()
end
end)
end
setupInput()
end
return CameraModule
Localscript (starter player folder):
-- LocalScript
local CameraModule = require(game.ReplicatedStorage:WaitForChild("CameraSwitchModule"))
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = game.Workspace.CurrentCamera
-- Adjust these variables for customization
local forwardOffset = 3
local upwardOffset = 1.5
-- Use the function from the module to set up the camera
CameraModule.setupCamera(character, camera, forwardOffset, upwardOffset)
project organization:
The issue is that, the toggleView change doesn’t work when I press the E key, and in addition to this, the variables
-- Adjust these variables for customization
local forwardOffset = 3
local upwardOffset = 1.5
it don’t make any changes. What is wrong?