Server script cannot find the object

I have an object in PlayerGui and trying to find it returns nil.

picture
a screenshot (while game is running) showing the blue key exists

--server script
proximityPrompt.Triggered:Connect(function(player)
		player.PlayerGui.Inventory.MainFrame.ItemFrame:WaitForChild("Blue Key"):Destroy()
end)
1 Like

The server never sees the PlayerGui. Do it on the client instead.

2 Likes

I don’t know if this is a mistake or not, but it appears that you forgot to set up a variable for proximityPrompt

Either way, I decided to make a script under a Part’s ProximityPrompt that can detect the blue key once being found in its specific frame in order to get destroyed (it is also important to take note in advance of what @IAmBanFor_Devforum stated above too):

local proximityPrompt = script.Parent

local Players = game:GetService("Players")

proximityPrompt.Triggered:Connect(function(player)
	local Inventory = player.PlayerGui:FindFirstChild("Inventory")
	local MainFrame = Inventory.MainFrame
	local ItemFrame = MainFrame.ItemFrame
	
	local Blue_Key = ItemFrame:FindFirstChild("Blue Key")
	if Blue_Key then
		Blue_Key:Destroy()
		if Blue_Key == nil then
			print("Blue key is now destroyed")
		end
	end
end)

Demonstration:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.