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

How do make it so that when you don't at a brick, it disappears? (FirstPerson)

How to make a script that when a player looks at a brick, but looks away, the brick disappears? I've considered finding the lookvector of the character torso, but I don't know how to use it.

3 comments

0

there's only a lookvector to a camera

0

^ all cframes have lookvector.

0

any ideas?

2 answers

This can be a good use of mouse.Target. Target will tell you if the mouse is touching the part. So you can simply wait until the part is the target, then wait until the part is not the target.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local part = workspace:WaitForChild('Part')

while true do
	part.Transparency=0.5
	repeat wait(1/3) until mouse.Target == part
	print('Looking at part')
part.Transparency=0
	repeat wait(1/3) until mouse.Target ~= part
	print('Stopped looking at part')
end

I'm interested to know a better way, but this is the simplest way I can think of.

WorldToScreenPoint

local player = game.Players.LocalPlayer
local cam = Workspace.CurrentCamera
local part = Workspace.Part

cam.Changed:connect(function()
	local pos, visible = cam:WorldToScreenPoint(part.Position)
	-- Tells you where the brick is on your screen and whether it's visible to the user
	-- If the brick is anywhere on your screen, then you're looking near or at it.
	part.Transparency = visible and 0 or 1
	-- if you aren't looking at it, then make it transparent, if you are, make it visible.
end)

3 comments

0

what does the script do?

0

Visible returns true or false if the brick is visible within your screen. If it returns false, then the brick isn't visible on your screen, ie you aren't looking at or near it.

0

where do i put the script? and is it a local script? (sorry if im being annoying, i just really want to know how to do this)

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