I made a prox prompt that gives the player a tool, but how do I make it to where if they have it the prompt disappears for that player only. Same for everyone else. This is the code I'm using to give the player the tool. I tried checking the backpack for the child which is the tool name and then destroying the prompt, but I think that would destroy it for everyone. Any help?
local tool = game.ServerStorage.Wrench local prompt = script.Parent.ProximityPrompt local function pickup(player) tool:Clone().Parent = game.Workspace[player.Name] end local player = game:GetService("Players") prompt.Triggered:Connect(pickup) local Tool = player.BackPack:FindFirstChild("Wrench") if player.BackPack.Child == Tool then prompt:Destroy() end
You can achieve this two different ways.
if
conditional within your pickup
method.Using Debounce
You can use debounce to toggle if something should be in a sort of off/on state.
local debounceTable = [] local function pickup(player) if debounceTable[player] then return end debounceTable[player] = true -- give player the tool end
Using if
conditional
You can move your check inside of the method, instead of trying to delete it.
local function pickup(player) local tool = player.Backpack:FindFirstChild("Wrench") local equippedTool = player.Character:FindFirstChild("Wrench") -- We may later find the player enter the proximity prompt and have the tool equipped. if not tool and not equippedTool then -- give player the tool end end