#Part Activated by Key tool

1 messages · Page 1 of 1 (latest)

old girder
#

Hi, I'm trying to create a part that can be triggered via proximity prompt, but needs a key tool either in the backpack or equipped on the character, this is the code:

'''lua
local keybutton = script.Parent
local prompt = keybutton.ProximityPrompt
local key = game.Workspace.Key
local handle = key.Handle

prompt.Triggered:Connect(function(player)
if player.Backpack:FindFirstChild("Key") or player.Character:FindFirstChild("Key") then
print("Success")
else
print("Fail")
end
end)
'''

it works if it's not equipped and is in the backpack but it prints nothing if the player equips it, this code is reused from another part that works the same way, however that one works, this is the code:

'''lua
local cooler = script.Parent
local prompt = game.Workspace.cooler.ProximityPrompt
local coolant = game.Workspace.coolant
local handle = coolant.Handle

prompt.Triggered:Connect(function(player)
if player.Backpack:FindFirstChild("coolant") or player.Character:FindFirstChild("coolant") then
print("Filled")
else
print("You do not have any coolant")
end
end)
'''

this code works, but the key one doesn't.

Any help is appreciated thank you!

cobalt sigil
old girder
old girder
# cobalt sigil Ye

Then I don’t really understand the problem with the code, I put it under player.Character:Findfirstchild(“key”)

old girder
#

It prints nothing if the key is equipped

old girder
pliant ibex
old girder
pliant ibex
old girder