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

GUI that shows what parts are within a vicinity?

Asked by 5 years ago

What would be a smart route to take when trying to show, through GUI Text Labels, what "items" are around you.

My first instinct was to go with a htibox on the items and then put the item in the "Vicinity" Gui, however trying to keep everything local for GUI sake that might not be the best option. My initial attempt was this inside of the "Rock" part:


local rock = script.Parent local hitBox = script.Parent:FindFirstChild("HitBox") local RS = game:GetService("ReplicatedStorage") local vicSlot = RS.VicinitySlot:Clone() script.Parent.ClickDetector.MouseClick:Connect(function(plr) print("Got Rock") end) hitBox.Touched:Connect(function (hit) if hit.Parent:FindFirstChild("Humanoid") then local vic = hit.Parent.PlayerGui.TAB_Menu.Vicinity --Then I thought I could replicate the item name and image to the first open "Vicinity" slot. Obviously this doesn't work because PlayerGui is not a valid member of Model. end end)

I understand the Vicinity GUI part should just be all client side just not sure how. I'm currently just looking into any ways for the LocalPlayer to detect items within a certian area around them. Similar to the hitbox idea but on the client side? I appreciate any help.

The rest of the GUI stuff I don't think is important to include for this problem but let me know if anything additional will help or left something out.

0
use magnitude theking48989987 2147 — 5y
0
so, basically, you are trying to make a gui tell text RetroGalacticGamer 331 — 5y
0
explain more RetroGalacticGamer 331 — 5y
0
@theKing, can you explain a bit more? i know your saying check mag and if item is 'in Range' then its 'in Vicinity', when am I checking this? continuously on all items? GoodCallMrOlsen 70 — 5y
View all comments (3 more)
0
magnitude is basically the distance formula, it finds every instance near another instance and calculates the distance between them DeceptiveCaster 3761 — 5y
0
@Dom, I'm trying to check "If an item in the workspace is within a certain vicinity, lets say 20 studs, of the player" I can undestand the GUI stuff in general its the check I am not fully understanding. My initial attempted checked via the server (the "rock" part that is in the workspace and if anything touches its "hitbox" which is just a transparent part around it) But I wanna keep it local GoodCallMrOlsen 70 — 5y
0
@MC "it finds every instance near another instance and calculates the distance between them", I've only known it to be like (posA-posB).Magnitude. Would I loop this or I guess my question am i just checking the mag of the player and every item no matter the distance? I guess i'm lost on when/how much to be checking the mag of all the items to find the ones close enough to be in vicinity GoodCallMrOlsen 70 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Since I don't technically know what vicSlot and hitbox actually are, I'm going to write a way to see which items you're aiming your mouse towards

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

workspace:WaitForChild(player.Name)

while true do
    local target = mouse.Target
    if target ~= nil and target.Name ~= "Baseplate" then
        local distance = (player.Character.HumanoidRootPart.Position - target.Position).magnitude
        if distance <= 20 then
            script.Parent.ScreenGui.TextLabel.Text = target.Name
        end
    end
    wait()
end

The wait for the player character allows the while loop to function properly, though you could change this to an activated event.

As stated within the comments, I am using a magnitude to check the distance between the player (more specifically their HumanoidRootPart) and the object.

The target ~= nil is used to prevent an error that occurs when pointing this at the Skybox, again this can be prevented by using an activated event.

The plus-side to this code is that you can place it into a LocalScript (since all parts in the Workspace are replicated to the Client at the server's start), mine is parented in the StarterGui for this example.

Ad

Answer this question