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.
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.