I have a script that let's you pick a tool up from the replicated storage by holding e on a model. but you can get tons of that tool if you keep repeatedly pressing e, which can give you more than that 1 tool. i want to make it so you only can have 1 of that tool and can't get no more.
this is the script for the ProximityPrompt
local ReplicatedStorage = game:GetService ("ReplicatedStorage") local keyTool = ReplicatedStorage.Keycard
local KeyPart = script.Parent
KeyPart.ProximityPrompt.Triggered:Connect (function(player) local keyCopy = keyTool:Clone() keyCopy.Parent = player.Backpack
1 | end ) |
please help!
heres my take on the script. Put this script (not local script) inside the KeyPart
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local KeyTool = ReplicatedStorage.Keycard |
03 |
04 | local KeyPart = script.Parent |
05 | local Prompt = KeyPart.ProximityPrompt |
06 |
07 | Prompt.Triggered:Connect( function (player) |
08 | local bp = player.Backpack |
09 | if bp:FindFirstChild( "Keycard" ) or player.Character:FindFirstChild( "Keycard" ) then -- checks if the player already has Keycard |
10 | return -- does nothing if player already has Keycard |
11 | else -- if player doesn't have keycard |
12 | local KeyCopy = KeyTool:Clone() |
13 | KeyCopy.Parent = bp |
14 | end |
15 | end ) |
if you want the player to keep the keycard until they leave, do this:
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local KeyTool = ReplicatedStorage.Keycard |
03 |
04 | local KeyPart = script.Parent |
05 | local Prompt = KeyPart.ProximityPrompt |
06 |
07 | Prompt.Triggered:Connect( function (player) |
08 | local sg = player.StarterGear |
09 | if sg:FindFirstChild( "Keycard" ) then -- checks if the player's startergear contains Keycard |
10 | return -- does nothing if player already has Keycard |
11 | else -- if player doesn't have keycard |
12 | local KeyCopy = KeyTool:Clone() |
13 | KeyCopy.Parent = sg |
14 | end |
15 | end ) |
This may require some knowledge on dictionaries, but here is a script with some explanations.
01 | local Part = script.Parent |
02 | local ProximityPrompt = Part.ProximityPrompt |
03 |
04 | --The Tool |
05 | local Tool = Part.Tool |
06 |
07 | --Use A Dictionary To Record Whoever Already Has the Tool |
08 | local playerWhoHasTools = { |
09 |
10 | } |
11 |
12 | --Create Event |
13 | ProximityPrompt.Triggered:Connect( function (player) |
14 | --Check dictionary to see if player already has tool |
15 | if not playerWhoHasTools [ player.Name ] then |