Hi. I am trying to make it so that when a player hovers over an ore while the tool is equipped, then it will change the gui's text to whatever ore it was. The ore is a model, hence the Parent.Name.
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 ore = {"BaseOreRock", "CopperOre", "IronOre", "SilverOre", "GoldOre", "EmeraldOre", "RubyOre", "SapphireOre", "DiamondOre", "PlatinumOre"} 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.Parent.Name == ore then gui.Text = cursorObject.Name else gui.Text = "None" end end) end) end)
Hello again, If you're trying to ask whether the Item is in a table, this is what you would do:
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 ore = {"BaseOreRock", "CopperOre", "IronOre", "SilverOre", "GoldOre", "EmeraldOre", "RubyOre", "SapphireOre", "DiamondOre", "PlatinumOre"} 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 for _,ore in ipairs(ore) do --// runs through table 'ore', if the cursorPos' parent's name is equal to whatever index it's currenty running through, then let it pass if cursorPos.Parent.Name == ore then gui.Text = cursorObject.Name end end else gui.Text = "None" end end) end) end)
Nice to help you once again, don't forget to accept and upvote if it helped, I'll help you with anything else if you need!
tool.Equipped:Connect(function() cursor.Move:Connect(function(mouse) cursorPos = cursor.Target pcall(function() local cursorObject = cursorPos local FoundOre = false for _,iore in pairs(ore) do if cursorObject.Parent.Name == iore then print(cursorObject.Parent.Name) gui.Text = cursorObject.Parent.Name FoundOre = true end end if FoundOre == false then gui.Text = "None" end end) end) end)
You cannot name the Value and the Table the same thing. If this helped, upvote/accept it!
ore
is a table, so you would have to make a generic for loop for it.
function CheckIsOre(obj) for i, v in pairs(ore) do -- Loops through the table if obj.Name == v then -- Checks if the name is the same with the value return true -- Returns true end end return false -- If no match is found, return false end
And to check it,
if CheckIsOre(cursorObject.Parent) then
Hope this helps and if it did, don't forget to accept :)
This is what I have so far. Added for i,v but now it only outputs the last ore to the gui, rather than every other ore when the mouse is hovered. Every other ore works when printed though..
tool.Equipped:Connect(function() cursor.Move:Connect(function(mouse) cursorPos = cursor.Target pcall(function() local cursorObject = cursorPos for _,ore in ipairs(ore) do if cursorObject.Parent.Name == ore then print(cursorObject.Parent.Name) gui.Text = cursorObject.Parent.Name else gui.Text = "None" end end end) end) end)