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

How to Manipulate Camera on an if statement?

I'm not that sure what to title the Question but i'll explain.

So, I'm fairly new to creating Camera Manipulation. My goal was to manipulate the camera when the detector is enabled, and after 3s, will go back to the player.

I've placed the script in StarterPlayerScripts, and is a LocalScript.

The Outcome was that it did not work at all.

local detector = game.workspace.BlahBlah
local camera = game.workspace.CurrentCamera
local camerapart = game.workspace.CameraPart
local player = game.Player.LocalPlayer

if detector.Enabled == true then
	camera.CameraType = "Fixed"
	camera.Focus = camerapart.CFrame
	wait(3)
	camera.CameraType = "Custom"
	camera.CameraSubject = player.Character.Humanoid
end

1 answer

✓ Accepted answer

You could do:

detector:GetPropertyChangedSignal("Enabled"):Connect(function()
	if detector.Enabled == true then
		camera.CameraType = "Fixed"
		camera.Focus = camerapart.CFrame
		wait(3)
		camera.CameraType = "Custom"
		camera.CameraSubject = player.Character.Humanoid
	end
end)

:GetPropertyChangedSignal Detects when the detectors value is updated, and if it equals true, then it'll continue doing what you want.

2 comments

0

at first didn't work but the problem was the player local so i placed it in the function. It worked but something off-topic is that the face of the camera keeps directing at the back

0

Can you elaborate on what you mean by "directing at the back"

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