How to make a "item picked up" message when you pick an item up(proximity prompt)

So what I am trying to achieve is basically make a message pop-up when you pickup an item from the ground using proximity prompts, not clickdetector. At the moment, its basically going to be a “click E to pickup” and it will display a gui which is inside the tool itself, and after a couple of seconds the message fades away. I managed to make a script for a clickdetector which makes it so that the clickdetector can open a gui, but don’t know how to apply that same concept to a proximity prompt.

Script for clickdetector:

	for i,v in pairs (script.Parent:GetChildren()) do
		if v.ClassName == "ScreenGui" then
			c = v:Clone()
			c.Parent = click.PlayerGui
		end
	end
end
script.Parent.ClickDetector1.MouseClick:Connect(onClick)```
1 Like

Just use a triggered event instead of MouseClick
``
script.Parent.ProximityPrompt.Triggered:Connect(function etc.)

2 Likes

I tried that and ended up with this script:

local Note = script.Parent
local tool = script.Parent.Parent.Parent.Parent.Parent
local ProximityPrompt = script.Parent.Parent.Parent.Parent
local Key = script.Parent.Parent.Parent.Parent.Parent.Parent

ProximityPrompt.Triggered:Connect(function(Plr)
	for i,v in pairs (script.Parent.Parent.Parent.Parent:GetChildren()) do
		if v.ClassName == "ScreenGui" then
			c = v:Clone()
			c.Parent = ScreenGui.PlayerGui
			end
		end
	end) 

But for some reason, I’ve ran into this error:

1 Like

Reference the PlayerGui instead

Also I don’t know if it’s just me but ScreenGui is not a global variable inside the script your sent

local Note = script.Parent
local tool = script.Parent.Parent.Parent.Parent.Parent
local ProximityPrompt = script.Parent.Parent.Parent.Parent
local Key = script.Parent.Parent.Parent.Parent.Parent.Parent

ProximityPrompt.Triggered:Connect(function(Plr)
    local PlayerGui = Player.PlayerGui
	for i,v in pairs (script.Parent.Parent.Parent.Parent:GetChildren()) do
		if v.ClassName == "ScreenGui" then
			c = v:Clone()
			c.Parent = PlayerGui.ScreenGui
			end
		end
	end) 
end)
3 Likes

Yeah it says ScreenGui is not a global variable and I’m not sure how to fix that, keep in mind my old script was

   for i,v in pairs (script.Parent:GetChildren()) do
   	if v.ClassName == "ScreenGui" then
   		c = v:Clone()
   		c.Parent = click.PlayerGui
   	end
   end
end
script.Parent.ClickDetector1.MouseClick:Connect(onClick)

local function onTrigger(player)
    for i,v in pairs (script.Parent:GetChildren()) do
       	if v.ClassName == "ScreenGui" then
       	   c = v:Clone()
       	   c.Parent = player.PlayerGui
        end
    end
end 

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
    onTrigger(player)
end)
2 Likes

So I was able to tweak your script and it worked! But now when I combine the whole script together I’m able to pick up the item but the message won’t appear. Here’s the script:

local handle = script.Parent.Handle
local Text = script.ScreenGui.Frame.Text
local Fade = script.ScreenGui.Frame.Text.Fade

if Key.Parent == workspace then
	local proxprompt = Instance.new("ProximityPrompt")
	proxprompt.Parent = handle
	proxprompt.KeyboardKeyCode = Enum.KeyCode.E
	proxprompt.ActionText = "Pick up"
	proxprompt.HoldDuration = .5
	proxprompt.ObjectText = "Blue Key"

	proxprompt.Triggered:Connect(function(Plr)
		local backpack = Plr:WaitForChild("Backpack")
		Key.Parent = backpack
		
		local function onTrigger(player)
			for i,v in pairs (script.Parent:GetChildren()) do
				if v.ClassName == "ScreenGui" then
					c = v:Clone()
					c.Parent = player.PlayerGui
				end
			end
		end 

		proxprompt.Triggered:Connect(function(player)
			onTrigger(player)
		end)
		Fade.Disabled = false
		proxprompt:Destroy()
	end)
end
local handle = script.Parent.Handle
local Text = script.ScreenGui.Frame.Text
local Fade = script.ScreenGui.Frame.Text.Fade

if Key.Parent == workspace then
	local proxprompt = Instance.new("ProximityPrompt")
	proxprompt.Parent = handle
	proxprompt.KeyboardKeyCode = Enum.KeyCode.E
	proxprompt.ActionText = "Pick up"
	proxprompt.HoldDuration = .5
	proxprompt.ObjectText = "Blue Key"
		
	local function onTrigger(player)
        Key.Parent = player.Backpack

		for i,v in pairs (script.Parent:GetChildren()) do
			if v.ClassName == "ScreenGui" then
				c = v:Clone()
				c.Parent = player.PlayerGui
			end
		end
	end 

	proxprompt.Triggered:Connect(function(player)
		onTrigger(player)
        Fade.Disabled = false
		proxprompt:Destroy()
	end)
end

Why did you add two triggered controls? You maked a variable of the backpack with another triggered control when you could make it inside of the onTriggered function, anyways this should work.

2 Likes