Making a pickup system for a game and keep getting this error in the output: 00:02:31.512 - ServerScriptService.PickUpServerScript:16: attempt to index nil with 'FindFirstChild'
here is the script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PickupEvent = ReplicatedStorage:WaitForChild("PickupItem")
local SlotsFolder = game:GetService("ServerStorage"):FindFirstChild("ItemSlotsUI")
local SlotUIDictionary = {
Water = SlotsFolder:FindFirstChild("Water")
}
local MagDist = 10
PickupEvent.OnServerEvent:connect(function(player, item)
print(item)
local Dist = player:DistanceFromCharacter(item.Handle.Position)
local playerGui = player:WaitForChild("PlayerGui")
local MainFrame = playerGui:FindFirstChild("MainFrame")
if Dist <= MagDist then
if MainFrame:FindFirstChild(item) then --ERROR IS HERE
print('found')
else
print('not found')
end
end
end)
Give any suggestions, thanks :)

3 comments
Took out the error, thanks. However there is an infinite yield so it doesn't print 'found' or 'not found' anyway to solve that?
Well, infinite yield means that there is no object called by name, 'MainFrame'. Double check whether MainFrame is in StarterGui. If yes, try finding it while testing in Studio, in PlayerGui. And lemme know the results.
ah should've known, I was finding MainFrame in playerGui instead of the ScreenGui it was located in, so sorry for the inconvenience since I'm a little bit tired, anyways, Thanks! :)