I want my script to find an IntValue called “dmg” (short for “damage”) but I keep running into errors like this:
04:54:38.726 Workspace.Fish.ProximityPrompt.Main:51: attempt to call missing method 'FindFirstChild' of table - Server - Main:51
here is a part of my code that I just need help with…
prox.Triggered:Connect(function(plr)
local hook = plr.Backpack:GetChildren()
for i = 1, #hook do
print(i, hook[i].Name)
end
local StopGui = plr.PlayerGui.ScreenGui.StopFishing
local FishingV = plr.FishingParts
local dmg = hook:FindFirstChild("dmg")
end)
Loop through “hook” table and do what you were doing with the FindFirstChild
or, you can do plr.Backpack:FindFirstChild(“name”, true) for recursive search under Backpack.
The error you are experiencing is because “hook” is a table, a table does not have the function “FindFirstChild”, but its children do!
To correct it you have to loop through the children:
local dmg
for _, child in ipairs(hook) do
dmg = child:FindFirstChild("dmg") -- check if dmg exists under the child
if dmg then break end -- break out of the loop because we found dmg
end
-- use dmg variable/value
But it is easier to just use FindFirstChild recursive:
local dmg = Backpack:FindFirstChild("dmg", true) -- true for "recursive mode"