how would I make a proximity prompt make you pick up a dropped tool? and not be able to walk on a tool to pick it up?
Make a proximity promot, then have it clone over to the tool whenever it is dropped. When the prompt finishes, move the tool to the player’s backpack.
sorry im new, can you show an example of the programming for this?
You can take a look at 1 of the official guides that provides all the basic information about how ProximityPrompts work
Usually what I do, is that I first create a Tool Prop which will handle the .Triggered Event for our ProximityPrompt
instance inside our Prop:
This is something that I have on 1 of my games, and the MainScript
handles the Tool Cloning & Parenting to the Player’s Backpack object
A SelectionBox is optional to use, but it’ll definitely make it way easier to indicate it as a collectable object as it renders a 3D Box around your Tool’s Handle
You’d want to store your actual Tool Object inside somewhere secure, preferably within ServerStorage if possible as that’s only visible to the server side & it can also prevent exploiters from obtaining the Tool(s)
Now, let’s get onto the coding here
Something to keep in mind, is that the .Triggered
Event has 1 parameter which is the Player object that originally fired the Event
Now, a couple of important objects that we’ll use for the Player here are:
- The Backpack, which holds a individual Player’s inventory
- The StarterGear (Optional), where if we ever want the Tool saved in our inventory even when we die it’ll still stay in our inventory
We’re gonna have to put this Script inside our Tool Prop firstly, and adding some code here…
local Tool = script.Parent
local ProxPrompt = Tool:WaitForChild("ProximityPrompt")
-- Here are a couple of custom properties that could be handy to you
local SaveAfterDeath = false -- If set to "true", then the Tool will also be cloned into the StarterGear
local DeleteAfterGrab = false -- If set to "true", the Tool Prop will be deleted after someone obtains it
local CanObtainMultiple = false -- If set to "true", the Tool Prop is able to clone the same tool multiple times
local ToolName = "Tool Name Here"
local function CloneTool(Plr)
local ToolCheck = game.ServerStorage:FindFirstChild(ToolName) -- We should make sure that the Name should be the same within our Tool that's inside "ServerStorage"
local Backpack = Plr:WaitForChild("Backpack")
local StarterGear = Plr:WaitForChild("StarterGear")
local Char = Plr.Character
if ToolCheck ~= nil and Char then -- If it's inside and we have a valid Character, then we can clone it! But we should first check if the Player has it >:O
-- Now this is where it gets a little tricky, cause the Tool can actually be parented to 2 areas: The Player's Backpack, or the Player's Character so we want to check for both of those:
local DuplicateCheck = Backpack:FindFirstChild(ToolName) or Char:FindFirstChild(ToolName)
if DuplicateCheck == nil then -- "nil" is basically non-existant, or not valid :P
local ToolClone = ToolCheck:Clone()
ToolClone.Parent = Backpack
end
-- Now here, we're gonna add a couple more checks for our custom properties:
if SaveAfterDeath then -- Will only run if set to "true"
local StarterClone = ToolCheck:Clone()
StarterClone.Parent = StarterGear
end
if DeleteAfterGrab then -- Will only run if set to "true"
Tool:Destroy()
end
if CanObtainMultiple then
local SecondaryClone = ToolCheck:Clone()
SecondaryClone.Parent = Backpack
end
else
warn("The specified Tool has not been found inside ServerStorage! Tool Name:", ToolName) -- If for some reason the tool isn't stored correctly, reply back with a warning!
end
end
ProxPrompt.Triggered:Connect(CloneTool)
So what we’re doing here, is we’re connecting our function to an Event by connecting it to our .Triggered
Event, and we’re also creating a couple of local variables
beforehand so that we can easily get to them
I also included in a couple of Custom Properties as well if you ever so need to use them, and they’re just bools so you can set them to true
or false
Most of the code that I wrote I put with comments, so that you can hopefully get a good ground of it
This should be a decent start for you to get a better understanding on how it works, and if you’ve managed to do everything correctly then…
Hopefully you’ve done it! And if you have any questions feel free to ask
Thank you for the amazing layout and setup explanation really helped, but from the video it seems like the thing you collect from itself isn’t effected by gravity, my main want is for example a tree is cut down and stick tools fall but you can’t walk over them to collect them like usually, you have to use proximity prompt to pick them up
Ah, well my example was just setting the Anchored property to true
as it’s not affected by physics in any sort of way
For your scenario, I mean all you’d just need to do is set your stick tools’ Anchored
property to false
, and CanCollide property to true
to have it affected by gravity as you stated before
It just all depends on what exact Tool Prop you’re using, and the Properties that go along with it as well
Alright thank you that was a very nice example tutorial and example you should make tutorials
WaitForchild is not a valid member of Player “Players.countdrums” is the error I am getting heres the code I edited it so it would work a bit better
local Tool = script.Parent
local ProxPrompt = Tool.Handle.ProximityPrompt
-- Here are a couple of custom properties that could be handy to you
local SaveAfterDeath = false -- If set to "true", then the Tool will also be cloned into the StarterGear
local DeleteAfterGrab = true -- If set to "true", the Tool Prop will be deleted after someone obtains it
local CanObtainMultiple = false -- If set to "true", the Tool Prop is able to clone the same tool multiple times
local ToolName = "Wood"
local function CloneTool(Plr)
local ToolCheck = game.ServerStorage:FindFirstChild(ToolName) -- We should make sure that the Name should be the same within our Tool that's inside "ServerStorage"
local Backpack = Plr:WaitForChild("Backpack")
local StarterGear = Plr:WaitForchild("StarterGear")
local Char = Plr.Character
if ToolCheck ~= nil and Char then -- If it's inside and we have a valid Character, then we can clone it! But we should first check if the Player has it >:O
-- Now this is where it gets a little tricky, cause the Tool can actually be parented to 2 areas: The Player's Backpack, or the Player's Character so we want to check for both of those:
local DuplicateCheck = Plr.Backpack:FindFirstChild(ToolName) or Char:FindFirstChild(ToolName)
if DuplicateCheck == nil then -- "nil" is basically non-existant, or not valid :P
local ToolClone = ToolCheck:Clone()
ToolClone.Parent = Backpack
end
-- Now here, we're gonna add a couple more checks for our custom properties:
if SaveAfterDeath then -- Will only run if set to "true"
local StarterClone = ToolCheck:Clone()
StarterClone.Parent = StarterGear
end
if DeleteAfterGrab then -- Will only run if set to "true"
Tool:Destroy()
end
if CanObtainMultiple then
local SecondaryClone = ToolCheck:Clone()
SecondaryClone.Parent = Backpack
end
else
warn("The specified Tool has not been found inside ServerStorage! Tool Name:", ToolName) -- If for some reason the tool isn't stored correctly, reply back with a warning!
end
end
ProxPrompt.Triggered:Connect(CloneTool)
My bad, there was a couple typos that I forgot to fix
Try the script I sent again, it should work fine now
on scales of multiple it doesn’t seem to work, you see its a survival game and I wanted branches to be collectable but when u pick up one it works but 2 u don’t get a second
I see, if that’s what you wanted then you can completely comment out the DuplicateCheck
conditional check & the variable as well
Just change it so that the DuplicateCheck
sections look like this:
--local DuplicateCheck = Backpack:FindFirstChild(ToolName) or Char:FindFirstChild(ToolName)
--if DuplicateCheck == nil then -- "nil" is basically non-existant, or not valid :P
local ToolClone = ToolCheck:Clone()
ToolClone.Parent = Backpack
--end
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.