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
end)
please help!
heres my take on the script. Put this script (not local script) inside the KeyPart
local ReplicatedStorage = game:GetService("ReplicatedStorage") local KeyTool = ReplicatedStorage.Keycard local KeyPart = script.Parent local Prompt = KeyPart.ProximityPrompt Prompt.Triggered:Connect(function(player) local bp = player.Backpack if bp:FindFirstChild("Keycard") or player.Character:FindFirstChild("Keycard") then -- checks if the player already has Keycard return -- does nothing if player already has Keycard else -- if player doesn't have keycard local KeyCopy = KeyTool:Clone() KeyCopy.Parent = bp end end)
if you want the player to keep the keycard until they leave, do this:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local KeyTool = ReplicatedStorage.Keycard local KeyPart = script.Parent local Prompt = KeyPart.ProximityPrompt Prompt.Triggered:Connect(function(player) local sg = player.StarterGear if sg:FindFirstChild("Keycard") then -- checks if the player's startergear contains Keycard return -- does nothing if player already has Keycard else -- if player doesn't have keycard local KeyCopy = KeyTool:Clone() KeyCopy.Parent = sg end end)
This may require some knowledge on dictionaries, but here is a script with some explanations.
local Part = script.Parent local ProximityPrompt = Part.ProximityPrompt --The Tool local Tool = Part.Tool --Use A Dictionary To Record Whoever Already Has the Tool local playerWhoHasTools = { } --Create Event ProximityPrompt.Triggered:Connect(function(player) --Check dictionary to see if player already has tool if not playerWhoHasTools[player.Name] then local toolClone = Tool:Clone() toolClone.Parent = player.Backpack --Record player in dictionary so they don't get the tool again. playerWhoHasTools[player.Name] = true end --Create Event So When Human Dies, They Are Removed from the Dictionary local humanPart = player.Character:FindFirstChildOfClass("Humanoid") if humanPart then local humanEvent humanEvent = humanPart.Died:Connect(function() --Remove from Dictionary playerWhoHasTools[player.Name] = nil --Disconnect Event humanEvent:Disconnect() end) end end)