Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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.

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 Vulkarin 581 — 6y
0
o thanks Credit_worthy -2 — 6y
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. OldPalHappy 1477 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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
Ad
Log in to vote
-1
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
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)    
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. Nowaha 459 — 6y

Answer this question