I’m trying to have a flashlight point to where your camera is (aka follow your screen) and the attachment (which has the lightbulb) doesn’t move, any feedback helps!
I’ve tried playing around with different ways to change the CFrame using look vectors, EulerAngles, and just changing the CFrame of the attachment to my camera, and using ToWorldSpace, all of those haven’t worked out well for me (either not working, or the light completely going off my screen when turning)
Server Script:
game.ReplicatedStorage.UpdateCamera.OnServerEvent:Connect(function(plr,camera)
local player = plr
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local hrp = character.HumanoidRootPart
local light = hrp.Attachment.CFrame:ToWorldSpace()
local camera2 = camera:ToWorldSpace()
local X,Y,Z = camera:ToEulerAnglesXYZ()
local X1 = math.deg(X)
local Y1 = math.deg(Y)
local Z1 = math.deg(Z)
light = CFrame.new(camera2.Position.X,camera2.Position.Y,camera2.Z) * CFrame.Angles(X1,0,0) * CFrame.Angles(0,Y1,0) * CFrame.Angles(0,0,Z1)
end)
Local Script:
function updatelight()
local camera = workspace.Camera.CFrame
game.ReplicatedStorage.UpdateCamera:FireServer(camera)
end