Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is WorldToScreenPoint not refreshing?

Expected result: Check if the player is looking at a certain part every 0.1 second, if yes, print BRUH MOMENT, else print NOT A BRUH MOMENT

Actual Result: it only checks the first frame for if its within bounds

it checks the first frame, sees the part isnt on-screen (its behind the player) spams NOT A BRUH MOMENT

(theres no errors)

Code:

local Camera = workspace.Camera
local part = game.Workspace.statue
local _, withinScreenBounds = Camera:WorldToScreenPoint(part.Position)

while true do
	wait(0.1) --crappy solution aaa
	if withinScreenBounds then
		   		print("BRUH")
	else
				print("NOT A BRUH MOMENT")
	end
end

1 answer

✓ Accepted answer

Hey, I see the reason here. Since the script just started reading it will only record that first frame putting it in the while loop will cause the script to check again like putting print once in a script it's not going to repeat but putting it in a while loop will update it.

local Camera = workspace.Camera
	local part = game.Workspace.statue
	 
	while wait(0.1) do
	local _, withinScreenBounds = Camera:WorldToScreenPoint(part.Position)
	    if withinScreenBounds then
	                print("BRUH")
	    else
	                print("NOT A BRUH MOMENT")
	    end
	end

1 comment

0

Works flawlessly, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.