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

How do I make a prox prompt stop giving a tool?

Asked by 2 years ago
Edited 2 years ago

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

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

You can achieve this two different ways.

  • Using a debounce table or
  • Implementing an 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
0
When using the If conditional, whenever I run the game I get an error message about the Backpack: Workspace.Handle.Script:7: attempt to index nil with 'Backpack' ENERGYSAVERNANO 14 — 2y
Ad

Answer this question