I have hit a road block. I have a script that detects if a player has a tool in there backpack, and if they do then it runs code. But if the player equippeds the tool it gives me a error. What I don’t know is how can I find that tool when it is equipped.
My code
Script
PromptLeft.Triggered:Connect(function(player)
local success, Error = pcall(function()
if player.Backpack.Keycard then
if Debounce == false then
KeycardSuccess2:Play()
KeycardSuccess2.Ended:Wait()
DoorLeftOpen:Play()
DoorLeftOpen.Completed:Wait()
Debounce = true
else
KeycardSuccess2:Play()
KeycardSuccess2.Ended:Wait()
DoorLeftClose:Play()
DoorLeftClose.Completed:Wait()
Debounce = false
end
end
end)
if Error then
KeycardFailSound1:Play()
KeycardFailSound1.Ended:Wait()
end
end)
PromptLeft.Triggered:Connect(function(player)
local success, Error = pcall(function()
if player.Backpack.Keycard or player.Character.Keycard then
if Debounce == false then
KeycardSuccess2:Play()
KeycardSuccess2.Ended:Wait()
DoorLeftOpen:Play()
DoorLeftOpen.Completed:Wait()
Debounce = true
else
KeycardSuccess2:Play()
KeycardSuccess2.Ended:Wait()
DoorLeftClose:Play()
DoorLeftClose.Completed:Wait()
Debounce = false
end
end
end)
if Error then
KeycardFailSound1:Play()
KeycardFailSound1.Ended:Wait()
end
end)
When a player equips any tool, the parent of the tool will set to the player character
Found the error. My code just in case if somebody needs some help.
Button.MouseButton1Click:Connect(function(player)
local Success, Error pcall(function()
if player.Character.Keycard then
print("Yay")
-- Code
end
end)
local success, erro pcall(function()
if player.Backpack.Keycard then
print("Keycard")
-- Code
end
end)
end)