So i need a camera.CFrame.LookVector to fire a function when changed.
Here's the code after adding what the second answer suggested:
wait() local players = game:GetService("Players") local player = players.LocalPlayer local UserInputService = game:GetService("UserInputService") local ev = workspace.Events.FloatFruitEvents.FloatingE local ev2 = workspace.Events.FloatFruitEvents.FloatingoffE local ev3 = workspace.Events.FloatFruitEvents.FloatingEv local mouse = player:GetMouse() local character = player.Character UserInputService.InputBegan:Connect(function(key,gameProcessed) if(gameProcessed) then return end if key.KeyCode == Enum.KeyCode.F then local camera = workspace.CurrentCamera local camcf = camera.CFrame ev:FireServer(camcf) camera:GetPropertyChangedSignal("Orientation"):Connect(function() print("look vector changed") ev3:FireServer(camcf) end) end end) UserInputService.InputEnded:Connect(function(key,gameProcessed) if(gameProcessed) then return end if key.KeyCode == Enum.KeyCode.F then ev2:FireServer() end end)
It's a local script.
Turns out camera doesn't have a position/orientation property but camera's cframe does
local camera = workspace.CurrentCamera currentLookVector = camera.CFrame.LookVector camera:GetPropertyChangedSignal("CFrame"):Connect(function() if(camera.CFrame.LookVector ~= currentLookVector)then currentLookVector = camera.CFrame.LookVector print("look vector changed") end end)
The code works for detecting the 'part' orientation, but camera doesn't have orientation property, so this wouldn't work for camera, see edit above for proper answer
With CFrame, the first parameter of CFrame.new() is the position and the second parameter, the lookVector, is the orientation. So to check when the orientation changes we are going to check when the orientation property changes:
I tested it on a part below just so you can see how it works, but I'll include the code that should work for your situation.
part = game.Workspace.Part part:GetPropertyChangedSignal("Orientation"):Connect(function() print("look vector changed") end) --changing the look vector a bit just to test wait(4) part.CFrame = CFrame.new(part.Position, Vector3.new(4,4,4)) wait(4) part.CFrame = CFrame.new(part.Position, Vector3.new(10,10,10))
With a camera, it would be
camera = game.Workspace.CurrentCamera camera:GetPropertyChangedSignal("Orientation"):Connect(function() print("look vector changed") end)
I am pretty sure you can use :GetPropertyChangedSignal() to get the Vector3 of something. Example:
local function onPosChange() -- fire or do anything here end part:GetPropertyChangedSignal("Position"):Connect(onPosChange)
I am not 100% sure if this works, but you should try it.
Hopefully it does help!