local camera = Workspace.CurrentCamera
local player = game.Players.LocalPlayer
repeat wait() until player.Character local char = player.Character
while true do
dist = (camera.CoordinateFrame.lookVector - game.Lighting:GetSunDirection()).magnitude
if dist < 0.1 then
print(player.Name .. " looked at sun.")
end
wait()
end
COMMUNITY QUESTION
Sun glare isnt working, anyone help?
1 answer
I recommend adding an "else print(dist)" after line 7 (and then changing line 9 to be "wait(1)" so that your output window doesn't flood too quickly). If nothing prints out, there's a problem with lines 1-3 (I would suspect that you might be accessing the camera before it exists, for instance. If that's the case, move line 1 to after the 'repeat' loop.). Otherwise, the print statements will print out and perhaps you'll find that "dist < 0.1" is too small a range (though when I tested it, I was able to get below 0.1).
Instead of a while loop, consider using the .Changed event, which will only fire when the player moves their camera. Use it like this:
local player = game.Players.LocalPlayer
repeat wait() until player.Character local char = player.Character
local camera = workspace.CurrentCamera
camera.Changed:connect(function()
dist = (camera.CoordinateFrame.lookVector - game.Lighting:GetSunDirection()).magnitude
if dist < 0.1 then
print(player.Name .. " looked at sun.")
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Please user the Lua format by pressing the Lua button when giving us your code. Do not simply just post it. Also make sure you have indents, and notes so we know what you are trying to do.