Unable to detect tools value

My problem is that with my keycard code I cannot detect if the keycard is equipped or not, only if it is in the player’s backpack.
I have created a door system that to unlock it you must 1. Have the keycard in your inventory 2. you must use the proximity prompt *with it equipped.
My problem is I cannot change the value to see if the player is equipped (holding) the tool.
Code:

local player = game.Players.LocalPlayer
local Granted = game.Workspace.Sounds["Access Granted [Half-Life 1]"]
local Decline = game.Workspace.Sounds["Access Denied [Half-Life 1]"]
local DoorPart = game.Workspace.DoorTest
local NeonPart = game.Workspace.Keypad
local Prompt = NeonPart.ProximityPrompt
local TweenService = game:GetService("TweenService")

local tweenInfo1 = TweenInfo.new(1.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.In)

local tween1 = TweenService:Create(DoorPart, tweenInfo1, {Position=Vector3.new(-115.558, 10.372, -147.987)})
local tween2 = TweenService:Create(DoorPart, tweenInfo1, {Position=Vector3.new(-115.558, 3.572, -147.987)})

Prompt.Triggered:Connect(function(player)
	local Tool = player.Backpack:FindFirstChild("KeyCardLVL1") or player.Character:FindFirstChild("KeyCardLVL1")
	
	if Tool.Activated then -- I've tried equipped as well but it just results in an error.
		print("Keycard is yes")
		Decline.Playing = false
		Granted.Playing = true
		NeonPart.BrickColor = BrickColor.new(0.266667, 1, 0)
		tween1:Play()
		Prompt.Enabled = false
	end
end)

Prompt.Triggered:Connect(function()
	print("No keycard")
	Decline.Playing = true
end)


Tool.Equipped is an event, but tools when equipped go into the character, so you can use a FindFirstChild on the character to make it easier.

So would it look like

player.Character.tool.Equipped

or even

player.Character.tool:FindFirstChild("Equipped")

FindFirstChild FINDS a child, while Equipped is an entire event. Simply just use a

player.Character:FindFirstChild("tool")
player.Character:FindFirstChildWhichIsA("Tool")

Edit.

So in the code I can use it here:

if player.Character:FindFirstChild("tool") then
-- code stuff here

I’m sure both are fine to use.

It doesn’t even allow it to work, so I think this is a misunderstanding (on my end)

Remove the “Tool.Activated” because Activated is an event and it just checks if you click with the tool or not.

Prompt.Triggered:Connect(function(player)
	local Tool = player.Backpack:FindFirstChild("KeyCardLVL1") or player.Character:FindFirstChild("KeyCardLVL1")
	
	if player.Character:FindFirstChild("tool") then
		print("Keycard is yes")
		Decline.Playing = false
		Granted.Playing = true
		NeonPart.BrickColor = BrickColor.new(0.266667, 1, 0)
		tween1:Play()
		Prompt.Enabled = false
	end
end)

I fixed my code like that for the video, so it is not even detecting the event.

Uh, you need to do the actual name for the tool, just not “tool.”

Oh, shoot my bad I must have seen the local tool part and made that mistake.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.