local s = script.Parent
local gui = script.Parent.Parent
s.Visible = true
local plry = game.Players.LocalPlayer
local char = plry.Character or plry.CharacterAdded:Wait()
local head = char:FindFirstChild("Head") or char:WaitForChild("Head")
local rs = game:GetService("RunService")
rs.RenderStepped:Connect(function()
local cam = workspace.CurrentCamera
local lighting = game.Lighting
local sundir = cam.CFrame.p + lighting:GetSunDirection()
local screenpos = cam:WorldToScreenPoint(sundir)
s.Position = UDim2.new(0,screenpos.X,0,screenpos.Y)
local bupleft = 0 - s.AbsoluteSize.Y
local bupright = 0 - s.AbsoluteSize.X
local bdownleft = gui.AbsoluteSize.Y + s.AbsoluteSize.Y
local bdownright = gui.AbsoluteSize.X + s.AbsoluteSize.X
local rayprams = RaycastParams.new()
rayprams.FilterType = Enum.RaycastFilterType.Blacklist
rayprams.FilterDescendantsInstances = {char}
local raydir = lighting:GetSunDirection() * 99999
local raycast = workspace:Raycast(cam.CFrame.Position, raydir, rayprams)
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(0.05, Enum.EasingStyle.Linear)
if raycast and s.AbsolutePosition.X >= (bupleft or bupright) and s.AbsolutePosition.Y <= (bdownleft or bdownright) then
ts:Create(s, TweenInfo.new(0.01, Enum.EasingStyle.Linear), {Size = UDim2.new(0,0,0,0)}):Play()
else
ts:Create(s, ti, {Size = UDim2.new(0,850,0,850)}):Play()
end
end)
Everything else works perfectly, but the problem is: when I look at the direction opposite of the Sun's, the GUI appears. I kinda figured out why, but idk how to fix.

1 comment
I just replaced your changes with a simple if-then statement. It worked fine now. Thanks for the idea!