E to pick up object

Hey there, I want to know how to make that when player is looking at object he wants to pick up, he presses E and it picks up.

You shouldn’t rly ask ppl to script whole systems fkr you, sorry.

You can use a proximity prompt to put objects in a player’s inventory while they are pressing the E key here

Sorry, that you are blind, cause he didn’t ask for anyone to write that. He very clearly stated that he wants to know.

Sorry, mb, i thought he meant for us to write, it no need to be rude. I kinda also sais that bcus it was in Help and Feedback > Scripting Support but that was my mistake, Sorry.

It is scripting support? So what? He simply wanted to know the flow of this kind of thing, you immediately accused him of asking to be spoon-fed

Sorry, my mistake, ive just seen ppl ask for whole systems before, and the short topic kinda put my brain into that mode :joy: mb

Wassup man, I don’t know how to explain so here is a tutorial video (production by Jordi)

Tutorial

Greetings, fellow dev! It is fairly simple to achieve such a system.
You’re gonna need the following:

  • A collectible version of the item you want to give the player (which will show up within your game map)
  • A proximity prompt inside that collectible version in order to detect the pressing of the E key on your keyboard
  • An attribute for the collectible version which determines which item it is going to give you
  • The tool version of the item you want to give the player (which will be given to the player’s inventory)
  • A serverscript

To achieve the final result, you can simply detect whenever the ProximityPrompt is triggered, and give the player the item accordingly, and then destroy the visual map version of the item to create the illusion of “collecting”. Here’s an example:

local ServerScriptService = game:GetService("ServerScriptService")
--
local MapItem = workspace.MapItem
local ToolName = MapItem:GetAttribute("ToolName")
local ProximityPrompt = MapItem.ProximityPrompt
-- Assuming MapItem is a BasePart, otherwise the ProximityPrompt will not show up

ProximityPrompt.Triggered:Once(function(player)
	local tool = ServerScriptService:FindFirstChild(ToolName)
	-- Will return nil if it does not find the tool. Consider making a check.
	local backpack = player.Backpack
	local newTool = tool:Clone()
	newTool.Parent = backpack
	MapItem:Destroy()
end)

Keep in mind :Once is a connection that will only run once. If your item is static and you do not want it to be destroyed when it is collected, you should use :Connect

If your items spawn dynamically, you can structure such code to connect and execute periodically for each spawned item. If it is not, and your collectible items are instead static, you can make all your necessary connections when the script first runs, but that’s pretty much it!

I think I’ve figured everything out, we can basically check through local script when player is looking at the object and if he presses E it picks up