of     1   

MightyDantheman
#182291060Sunday, January 24, 2016 6:15 AM GMT

How would I detect if and which part my mouse cursor is pointing at (within a certain distance), and if I press the E button, something happens? I'm basically trying trying to make an object that you can pick up by pressing the "E" button while looking at it at a certain distance (that way you can't click on it half way across the map). ~MightyDantheman
MightyDantheman
#182292129Sunday, January 24, 2016 6:41 AM GMT

Can anyone at least tell me how to detect if a player is looking at an object? It doesn't have to be the cursor touching it, but I feel like that would be the easiest way to do so. ~MightyDantheman
Aethex
#182292225Sunday, January 24, 2016 6:43 AM GMT

If you want to see if the cursor touched it, then you can use the mouse's Moved event along with the mouse's property "Target" to check if the mouse is hovering over the object.
Aethex
#182292256Sunday, January 24, 2016 6:44 AM GMT

MightyDantheman
#182294136Sunday, January 24, 2016 7:31 AM GMT

Thanks, but those are both confusing to me (I'm used to the wiki when it shows you a script example). Is it possible to see an example or something that could explain this to me a little better? ~MightyDantheman
Aethex
#182294389Sunday, January 24, 2016 7:39 AM GMT

--localscript local plr = game.Players.LocalPlayer; local mouse = plr:GetMouse(); mouse.Move:connect(function() local tar = mouse.Target; if tar then if tar:FindFirstChild("keyPickupPart") then --insert something like a boolvalue name "keyPickupPart" in parts you want to pickup local uis = game:GetService("UserInputService"); uis.InputBegan:connect(function(inp) if inp.KeyCode == Enum.KeyCode.E then -- insert pickup code here end end) end end end)
Aethex
#182294431Sunday, January 24, 2016 7:40 AM GMT

oh, i didn't implement a distance check you can use DistanceFromCharacter for that: http://wiki.roblox.com/index.php?title=API:Class/Player/DistanceFromCharacter let me know if you need me to implement that for you too
MightyDantheman
#182295431Sunday, January 24, 2016 8:11 AM GMT

I can't seem to get this to work. I've tried this script in the local script: local plr = script.Parent.Parent local mouse = plr:GetMouse(); mouse.Move:connect(function() local tar = mouse.Target; if tar then if tar:FindFirstChild("keyPickupPart") then --insert something like a boolvalue name "keyPickupPart" in parts you want to pickup local uis = game:GetService("UserInputService"); uis.InputBegan:connect(function(inp) if inp.KeyCode == Enum.KeyCode.E then game.Workspace:ClearAllChildren( ) end end) end end end) --// and this script for a normal script: local plr = script.Parent.Parent local mouse = plr:GetMouse(); mouse.Move:connect(function() local tar = mouse.Target; if tar then if tar:FindFirstChild("keyPickupPart") then --insert something like a boolvalue name "keyPickupPart" in parts you want to pickup local uis = game:GetService("UserInputService"); uis.InputBegan:connect(function(inp) if inp.KeyCode == Enum.KeyCode.E then game.Workspace:ClearAllChildren() end end) end end end) --// I did put that boolvalue in. ~MightyDantheman
MightyDantheman
#182297542Sunday, January 24, 2016 9:29 AM GMT

Bump. ~MightyDantheman
Aethex
#182320258Sunday, January 24, 2016 6:16 PM GMT

why'd you do "plr = script.Parent.Parent"? My script used "game.Players.LocalPlayer" for the player. It also has to be used in a localscript, that server script you have won't work.
MightyDantheman
#182361503Monday, January 25, 2016 3:30 AM GMT

I tried it your way inside a local script and it still didn't work. But I got it to work my own way. Thank you for your help. ~MightyDantheman
AwesomeMe003
#215208258Monday, April 24, 2017 8:09 PM GMT

Whats the working script? I could really use it in a game Im making. :)

    of     1