Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to prevent players from picking up more than 1 tool?

Asked by 3 years ago

ibb.co/Tt3V5Xq

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

please help!

2 answers

Log in to vote
1
Answered by
NGC4637 602 Moderation Voter
3 years ago
Edited 3 years ago

heres my take on the script. Put this script (not local script) inside the KeyPart

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local KeyTool = ReplicatedStorage.Keycard
03 
04local KeyPart = script.Parent
05local Prompt = KeyPart.ProximityPrompt
06 
07Prompt.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
15end)

if you want the player to keep the keycard until they leave, do this:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local KeyTool = ReplicatedStorage.Keycard
03 
04local KeyPart = script.Parent
05local Prompt = KeyPart.ProximityPrompt
06 
07Prompt.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
15end)
0
i feel this is a lot simpler NGC4637 602 — 3y
0
yeah thanks anyways! the other guy helped me already. but if his doesn't work ever, i'll use yours superbubba2020 6 — 3y
0
You should probably use his solution, it's much more simple and can work across multiple parts in case you have multiple prompts that involve giving out your keycard. ArsonMcFlames 363 — 3y
0
on second thought, i tested your solution and it works the same, and it's a lot simpler like you said, and this guy^^^ is right. thanks! superbubba2020 6 — 3y
0
np NGC4637 602 — 3y
Ad
Log in to vote
1
Answered by 3 years ago

This may require some knowledge on dictionaries, but here is a script with some explanations.

01local Part = script.Parent
02local ProximityPrompt = Part.ProximityPrompt
03 
04--The Tool
05local Tool = Part.Tool
06 
07--Use A Dictionary To Record Whoever Already Has the Tool
08local playerWhoHasTools = {
09 
10}
11 
12--Create Event
13ProximityPrompt.Triggered:Connect(function(player)
14    --Check dictionary to see if player already has tool
15    if not playerWhoHasTools[player.Name] then
View all 33 lines...
0
this is hard to understand, but I'll try. thanks for helping? superbubba2020 6 — 3y
0
Where do i put this script? superbubba2020 6 — 3y
0
you put the script inside your KeyPart NGC4637 602 — 3y
0
OMG BRO I LOVE YOU (no homo) THANKS SO MUCH I UNDERSTAND IT AND IT WORKSS, YOU SAVED ME SO MUCH TIME RIGHT NOW AND FOR MY FUTURE KNOWLEDGE, now i know what dictionaries are! thank you superbubba2020 6 — 3y

Answer this question