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

How would I make it so when a player looks away from a npc, then the npc disappears?

So, what i'm trying to do is there is a npc, and when it is not visible on the camera anymore, then it will disappear. I tried raycasting, but I don't know where to start. Please help on what I should probably use, to achieve my goal. Thank you!

2 answers

✓ Accepted answer

Yes, scripting helpers is NOT a request site, but I thought this was a good question.

You could use WorldToScreenPoint) to see if the parts isn't in the player's view.

Code:

local withinScreenBounds = Camera:WorldToScreenPoint(part.Position)

if not withinScreenBounds then

end

2 comments

0

I get the property you mean, but I don't get why you use two variables and what withinScreenBounds means.

0

My apologies, I didn't notice that I added an addition variable. Also, withinScreenBounds is just a variable.

U could make a script ina a part, and ad a click detector (u can do this with UI, but i dont know how)

script.Parent.ClickDetector.MouseHoverLeave:connect(function() -- Detect Mouse Hover Leave.
script.Parent.Parent:Destroy() -- Destroy Parent.
end)

maybe (DownVotes come fast XD)

4 comments

0

does that giant "-1" mean i did it wrong? XD

0

yez

0

actually means someone down voted your answer, in this case bc it don't have a explanation

0

oh

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