How do I trigger a sound to play when a player is looking at an object?
COMMUNITY QUESTION
How to play a sound when looking at an object?
1 answer
Easy :D
local mousein = false
script.Parent.MouseHoverEnter:Connect(function()
mousein = true
end)
script.Parent.MouseHoverLeave:Connect(function()
mousein = false
end)
while wait() do
if mousein == true then
script.Parent.Parent.Sound.Playing = true
else
script.Parent.Parent.Sound.Playing = false
end
end
the script will work if the cube structure looks like this: https://ctrlv.cz/LeIT
If I helped, please mark my answer as correct :)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Please make effort to post your own code.
Preferably calculate with LockFirstPerson enabled; use a Raycast from the Character's head to the Cursor .Hit Vector3 (Position). Use RunService to perpetually track the Object of contact returned, and compare. Disconnect the signal listener after matched.