Issues with proximity Prompt

I would like to take this object by pressing E with the proximity prompt and have it added to the player’s backpack, what am I doing wrong?

The problem is that when I get closer it only equips and it does not work press E to equip it :confused:

image

image

image

script:

local Tool = script.Parent.Parent:FindFirstAncestor("toolName")
local proximityPrompt = script.Parent:FindFirstAncestor("ProximityPrompt")

local objectTouched = script.Parent:WaitForChild("objectTouched")
objectTouched:Destroy()

proximityPrompt.Triggered:Connect(function(Player)
	Tool.Parent = Player:WaitForChild("Backpack")
	proximityPrompt:Destroy()
end)

Maybe try using a function like this:

local function pickup()
    local tool = script.Parent.Parent
    local proxpromp = script.Parent.ProximityPrompt
    
    proxpromp.Triggered:Connect(function(plr)
            tool.Parent = plr:WaitForChild("Backpack")
    end
end

pickup()

I do not know about scripting proximity prompts at all, so what I just typed may have been useless, but I tried my best.

since you want a custom pickup, you also need a custom drop so you can return it into a model and then when you pick it up, it returns to a tool object. I have done this once and you can do it by making a module script of pick up so you can reuse the code in any other objects

in a module script, write this:

local module = {}

function module.PickupModule(item, proximityprompt, plr) -- item that you want to drop, 
    --and also the proximity prompt so you can disable it, also add the player
    local tool = Instance.new()
    tool.Name = item.Name -- copies the exact name of the item that is picked up
    for _, v in pairs(item:GetChildren()) do -- gets the children of the item
        v.Parent = tool
    end
    tool.Parent = plr.Backpack -- puts the tool in the backpack of the player who picked it up
    pp.MaxActivationDistance = 0
    tool.CanBeDropped =  false -- since you are going to make your own drop script
end

return module

name this ‘PickupModule’ and place it in the ServerStorage, but you can change it (i just named it this since i’m showing an example)

NOTE: this must be a module script

now inside your proximity prompt, add a server script and write this

ServerScript inside the proximity prompt

local pp = script.Parent -- the proximity prompt but since script is parented to the prompt
local pickmodule = require(game.ServerStorage.PickupModule)
local item = --item you want to pickup (this must be a model since you are going to turn it into a tool by getting all the child

pp.Triggered:Connect(function(plr))
    pickmodule.PickupModule(item, pp, plr)
end)

now, you need to make your own drop script to turn the tool into a model again.

you can do it with userinput service in a local script and then send a remote event from the client to server which drops the item the player is holding.

I hope this helps, lol.

1 Like

Hello! Your code looks a bit weird, with the

local objectTouched = script.Parent:WaitForChild("objectTouched")
objectTouched:Destroy()

There isn’t anything named “objectTouched” so you should of got a error like “Not a member of Handle”

Also with

local Tool = script.Parent.Parent:FindFirstAncestor("toolName")
local proximityPrompt = script.Parent:FindFirstAncestor("ProximityPrompt")

it’s best to do this because personally I never used “:FindFirstAncestor” and don’t know what it does and I 100% know if it works if I do parents.

local Tool = script.Parent.Parent
local proximityPrompt = script.Parent.ProximityPrompt

The triggering is correct let me put something here for you to try and see if it works

local Tool = script.Parent.Parent
local proximityPrompt = script.Parent.ProximityPrompt

proximityPrompt.Triggered:Connect(function(Player)
    local CloneTool = Tool:Clone()
    CloneTool.Parent  = Player:WaitForChild("Backpack")
    Tool:Destroy()
end)

Basically I made it clone the tool if the proximity prompt is triggered and gave it to the backpack then destroyed the tool off the floor.

Any problems or errors / mistakes please let me know! This is all made without testing it.

Thank you guys so much for your help! :smiley:

1 Like
local repStorage = game:GetService("ReplicatedStorage")
local Tool = repStorage:WaitForChild("Tool")
local proximityPrompt = script.Parent

proximityPrompt.Triggered:Connect(function(Player)
	local Backpack = Player:WaitForChild("Backpack")
	Tool.Parent = Backpack
	Tool.Parent = Player:WaitForChild("Backpack")
end)

Place the script inside the ProximityPrompt & place the tool in the ReplicatedStorage directory, like
this:

image

Thanks but does anyone know why when I walk on this part the object is automatically taken?

I would like it to be taken only if I press E with the proximity prompt and it is not working properly.

image

local handle = script.Parent.Parent.Handle
local selectionBox = Instance.new("SelectionBox")
selectionBox.Adornee = handle
selectionBox.Color3 = Color3.new(1,0,0)
selectionBox.Parent = handle

local function pickup()
	local tool = script.Parent.Parent
	local proxpromp = script.Parent.ProximityPrompt

	proxpromp.Triggered:Connect(function(plr)
		tool.Parent = plr:WaitForChild("Backpack")
		proxpromp:Destroy()
        selectionBox:Destroy()
	end)
end

pickup()

Which part? Show your explorer window please.

the item you want to pickup should be a model instead of just tool (so you can’t pick it up) and then when you drop it return it into a model, oh and also i recommend using module script so you can just use the module for every item you want to pickup.