Hello, am trying to figure out how to find an object that I set interactable in game. Mostly if someone is near an item and the mouse is over it, some gui will show up. If anyone can explain this for me or can show me an example would really help me.
I figured it out mostly, this returns any item near the character and his mouse over it.
01 | local function FindObjectNearMe(Player) |
02 | for i,v in pairs (workspace.ItemInWorld:GetChildren()) do |
03 | for e,u in pairs (v:GetChildren()) do |
04 | if (Player.Character.Torso.Position - u.Position).magnitude < = 8 then |
05 | if Mouse.Target = = u then |
06 | SelectedObject = u |
07 | else |
08 | SelectedObject = nil |
09 | end |
10 | end |
11 | end |
12 | end |
13 | end |
01 | local lp = game.Players.LocalPlayer |
02 | local mouse = lp:GetMouse() |
03 | local minDistance = 10 |
04 | mouse.Move:Connect( function () |
05 | local targ = m.Target |
06 | if targ and targ.Name = = "Interactable" and lp.Character and lp.Character:FindFirstChild( "HumanoidRootPart" ) then |
07 | if (lp.Character.HumanoidRootPart.Position-targ.Position).magnitude < = minDistance then |
08 | --show gui |
09 | end |
10 | end |
11 | end ) |