Hi. I am wondering how would you detect a part that is in the workspace with a tool equipped, and return that value to the player's gui? Thanks!
EDIT: I don't really know where to start, and would like some guidance. The player will be using a pickaxe. If the object the player's mouse is on, is an ore, then the game will let that ore get 'mined 'by the specific player. I am asking for the returned value to the player's gui since I want it to update based on what ore they are looking at, and how full the progress bar is.
This request with all will be a lot, I will only help you get started, this should be handled in the LocalScript aiding the use of the ‘Pickaxe
’, for this to work we’re going to use mouse.Target
, This returns whatever object the cursor is beneath.
I will be Scripting by the default structure of a Tool: Tool - Handle - LocalScript, remember that when Scripting a Tool, primarily just creating one, a BasePart
of the name, with a capital H, “Handle”.
local tool = script:FindFirstAncestor(“Pickaxe”) local handle = tool:WaitForChild(“Handle”) local equipped = false local player = game:GetService(“Players”).LocalPlayer local cursor = player:GetMouse() --// I prefer “cursor” local cursorPos = cursor.Target local oreGui = player:FindFirstChild(‘PlayerGui”).oreGui tool.Equipped:Connect(function() if not equipped then return end equipped = true if (oreGui) then spawn(function() while equipped wait(.5) do cursorPos = Cursor.Target end end); wait() while equipped wait(.5) do pcall(function() local cursorObject = cursorPos if (cursorObject:IsA(“BasePart”) and cursorObject.Name == “Ore”) then oreGui.Text = cursorObject.Name end end end end end)
This should get you started, creating this kind of cursorCheck, one I’m familiar with, is quite hard, but this will get you up on your feet, it has flaws but is functional, it’s up to you to finish it, I’m not going to write something that long, you understand, I hope this helps you out anyway, if so, don’t forget to accept this answer and upvote! Good luck
local tool = script.Parent local handle = tool.Handle local equipped = false local player = game.Players.LocalPlayer local cursor = player:GetMouse() local cursorPos = cursor.Target local gui = player:WaitForChild("PlayerGui"):WaitForChild("OreGui").TextLabel tool.Equipped:Connect(function() cursor.Move:Connect(function(mouse) cursorPos = cursor.Target pcall(function() local cursorObject = cursorPos if cursorObject.Name == "BaseOreRockTest" then gui.Text = cursorObject.Name end end) end) end)