Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

ServerScriptService.PickUpServerScript:16: attempt to index nil with 'FindFirstChild'?

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 :)

1 answer

✓ Accepted answer

Well, the error is trying to say that MainFrame is nil, in simple words, there is no 'MainFrame' or the script tried to index it before 'MainFrame' was loaded in PlayerGui. To fix the issue, on Line 14:

local MainFrame = playerGui:WaitForChild("MainFrame")

Lemme know if it helps!

3 comments

0

Took out the error, thanks. However there is an infinite yield so it doesn't print 'found' or 'not found' anyway to solve that?

0

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.

0

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! :)

This discussion is preserved as it was. New answers, comments, and votes are closed.