Is there some way to make object diseppear in the moment when player see it?
So I have an idea, haven't tested it yet, but you lock the player's camera so that the camera can only be turned with the players movement (forgot the name of the camera property). Then you raycast on the edge of the players fov so that when it detects an object it waits either .1 or faster and then turns the detected object transparent. If an object has already been detected and it is detected again, then it turns the object opaque again.
Mine is not the best answer, if you're talking about getting if a specific part is visible, but if you're talking about making every part in front of you invisible, then this is probably the best idea.
What you want is WorldToScreenPoint, which I wrote a little bit about here.
This can be used to return whether or not a part is visible on screen.
However, this doesn't take in to account parts that might be in the way - to solve this problem we can use GetPartsObscuringTarget.
Then finally, we want to run this locally on ever rendered frame, so we can use RenderStepped. Since this is running locally, it shouldn't place undue load on the server.
I wrote a little babby example - just put a brick in the workspace called "CanYouSeeMe", and put the code in a LocalScript in StarterPlayer.StarterPlayerScripts.
local seenPreviously = false player = game:GetService("Players").LocalPlayer function partSeen(p) local s = Instance.new("SelectionBox") s.Adornee = player.Character s.Parent = player.Character end conn = game:GetService("RunService").RenderStepped:Connect(function(t) if not seenPreviously then local target = workspace.CanYouSeeMe local camera = workspace.CurrentCamera local locationAndDepth, visible = camera:WorldToScreenPoint(target.Position) if visible then local obscuring = camera:GetPartsObscuringTarget({target.Position}, {target}) if #obscuring > 0 then -- not visible else -- visible seenPreviously = true partSeen(workspace.CanYouSeeMe) conn:Disconnect() end end end end)
Using both conn:Disconnect()
and seenPreviously
is doing the same thing twice, but one might be easier to use than the other depending on what you're doing.