I want to check my table from :GetChildren(). I want to see if the mouse's targeted brick or item is in the table I have.
I thought I could match the name of the target to the name in the table, but I don't know how to span my table like this. Would I just use a for loop?
player = game.Players.LocalPlayer
mouse = player:GetMouse()
Selected = script.Selected
ConsumeEvent = game.ReplicatedStorage.Consume
stat = script.Parent:WaitForChild("Stats")
local consumables = game.Workspace.Consumables:GetChildren() -- table here
mouse.Move:connect(function()
if mouse.Target ~= nil then
if mouse.Target.Name == consumables[WhatDoIPutHere].Name then -- main problem here
script.Parent.BrickStatus.Main.Visible = true
script.Parent.BrickStatus.Main.DisplayName.Text = mouse.Target.Name
script.Parent.BrickStatus.Main.Portions.Text = mouse.Target.Portions.Value
This is just a portion of the script. There's obviously ends at the end of all this.

5 comments
Did not realize players was a service. Thanks. This should work. I didn't know if a loop was the most efficient thing to do here. I appreciate the optimization recommendations. All of my code is from an old project I worked on way way back. This helps. Great work
No problem.
Hey, I did end up using this method. I spent the past 2 or so hours fixing my entire script to UserInputService. In regards to the loop, it caused tons of problems with my script because essentially I was looping everything within it. However, I did learn a lot about loops. But what I was trying to do was basically "cycle through" the table (in theory) or check my table to match mouse.target.
What I ended up using was k= table.find(tablename, mouse.target) to match it to a number value, then use an if table[k] then. That worked out perfectly. But for the amount of information I gave, your answer was perfectly acceptable, plus the tips helped. But I just thought I'd let you know about the solution I found.
Alright.