What I aim for is a script that detects if 4 parts are out of view of the player.
I have gotten what I wanted, but the script I wrote detects the player as “not looking” at all 4 parts even though the player can still see all 3 parts.
Let’s just say the green node in the image is out of view of the player, the script detects this as not looking, but there’s still 3 nodes in view. No clue if I explained that correctly.
I’m not great at scripting, but here’s the script I wrote.
NOTE: On_Screen_1,2,3 and 4 are the 4 parts you see in the image.
I have figured that if On_Screen_1 == true, this means this part is in view of the player.
while Searching do
local Touching = Detector:GetTouchingParts()
for i=1,#Touching do
if Touching[i] == HumanoidRootPart then
local On_Screen_1 = select(2, Camera:WorldToViewportPoint(Nodes.Node_1.Position))
local On_Screen_2 = select(2, Camera:WorldToViewportPoint(Nodes.Node_2.Position))
local On_Screen_3 = select(2, Camera:WorldToViewportPoint(Nodes.Node_3.Position))
local On_Screen_4 = select(2, Camera:WorldToViewportPoint(Nodes.Node_4.Position))
if On_Screen_1 then
On_Screen_1 = true
else
On_Screen_1 = false
end
if On_Screen_2 then
On_Screen_2 = true
else
On_Screen_2 = false
end
if On_Screen_3 then
On_Screen_3 = true
else
On_Screen_3 = false
end
if On_Screen_4 then
On_Screen_4 = true
else
On_Screen_4 = false
end
print(On_Screen_1)
print(On_Screen_2)
print(On_Screen_3)
print(On_Screen_4)
if On_Screen_1 == true and On_Screen_2 == true and On_Screen_3 == true and On_Screen_4 == true then
Looking = true
Player1_Event:FireServer(Looking)
print("Is looking")
else
Looking = false
Player1_Event:FireServer(Looking)
print("Is not looking")
end
end
end
wait(.5)
end
Honestly, if someone actually understands everything I just said they are a legend