Help needed with script that moves camera when E is pressed

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

A system in which when I press E it moves the camera to a part called “AimPart”

  1. What is the issue? Include screenshots / videos if possible!

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have gotten a script but it does not work:

-- Variables
local aimPart = workspace:WaitForChild("AimPart") -- Assumes the part is named "AimPart"
local camera = game.Workspace.CurrentCamera

-- Function to move the camera to the AimPart's position
local function moveCamera()
	local aimPosition = aimPart.Position
	camera:Interpolate(CFrame.new(camera.CFrame.Position, aimPosition), CFrame.new(aimPosition), 1) -- Adjust the interpolation speed as desired
end

-- Connect the function to a desired event that triggers the camera movement
-- For example, you can connect it to a button click event or a keyboard key press event
-- Here's an example of connecting it to the 'E' key press event
game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		moveCamera()
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Any errors in the output? Also im prtty sure camera doesnt have a function called Interpolate, I think you meant :Lerp()

I have tried that and there is no difference, I do see in the output this:

That error your getting right now means the game can’t find AimPart, are you sure it where it should be?

this is everything in the workspace:
image
either way I wouldn’t trust the script as for the source I got it from isn’t very good