Door with proximity prompt that checks players backpack for certain tool?

How would I make a simple script where whenever a door with a proximity prompt gets triggered, it checks the player’s backpack, and checks if it has a tool. If it doesn’t have the tool, it wont do anything. But if they do have the tool it’ll do something. How would I do that?

script.Parent.ProximityPrompt.Triggered:Connect(function()
– what do i put here?
end)

1 Like

All you need to do is check if the player has the item in their Backpack. I’d probably use an if not plr.Backpack:FindFirstChild(itemname) then but that only checks if its in the backpack. you would also need to check if they have it equipped. if not plr.Backpack:FindFirstChild(ItemName) and plr.Character:FindFirstChild(ItemName)

1 Like

If you’re unsure of how to go about writing something, look at the data you have to work with. The Triggered event fires with the player who triggered the prompt. You can use the player to get their backpack and then search for the tool with FindFirstChild.

1 Like

here’s what i made:

it works but it also doesnt. it checks my backpack and opens the door. THOUGH, if i have the tool EQUIPPED, and THEN i trigger it, it wont do anything.

script.Parent.ProximityPrompt.Triggered:Connect(function(player)
– what do i put here?
if player.Backpack:FindFirstChild(“Key”) then
script.Parent.Transparency = 1
script.Parent.CanCollide = false
script.Parent.Parent.door2.Transparency = 0
script.Parent.Parent.door2.CanCollide = true
wait(.001)
script.Parent.ProximityPrompt:Destroy()

end
end)

You have to include a or statement as well, since equipping a Tool will parent it to the Player's Character

Here’s the fixed script:

script.Parent.ProximityPrompt.Triggered:Connect(function(Player)
    if Player.Backpack:FindFirstChild("Key") or Player.Character:FindFirstChild("Key") then
        print(Player.Name.." has used the key!")
        script.Parent.Transparency = 1
        script.Parent.CanCollide = false
        script.Parent.Parent.door2.Transparency = 0
        script.Parent.Parent.door2.CanCollide = true
        wait(.001)
        script.Parent.ProximityPrompt:Destroy()
    else
        print(Player.Name.." does not have the key")
    end
end)

in the if statement, add or Player.Character:FindFirstChild("Key")

1 Like

thank you so much!!! i rlly needed this

1 Like