Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Sun glare isnt working, anyone help?

Asked by 9 years ago
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
0
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. AmericanStripes 610 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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)
Ad

Answer this question