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.
local function FindObjectNearMe(Player) for i,v in pairs(workspace.ItemInWorld:GetChildren()) do for e,u in pairs(v:GetChildren()) do if (Player.Character.Torso.Position - u.Position).magnitude <= 8 then if Mouse.Target == u then SelectedObject = u else SelectedObject = nil end end end end end
local lp = game.Players.LocalPlayer local mouse = lp:GetMouse() local minDistance = 10 mouse.Move:Connect(function() local targ = m.Target if targ and targ.Name == "Interactable" and lp.Character and lp.Character:FindFirstChild("HumanoidRootPart") then if (lp.Character.HumanoidRootPart.Position-targ.Position).magnitude <= minDistance then --show gui end end end)