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

How to find out if player is around intractable Objects in game?

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.

3 comments

0

Want to give it a try with some help? Only two real things you need for it http://wiki.roblox.com/index.php?title=Magnitude http://wiki.roblox.com/index.php?title=API:Class/Mouse/Target

0

o thanks

0

Those links are meh. Region3 is probably the best option for getting things around the character. Then you can loop through those instances and check if they're interactable.

2 answers

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)	

1 comment

0

Please explain to the person who asked the question what you are doing, so they actually know what it does instead of just copy and pasting it.

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