Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I find If the player has a certain Item equipped?

Ello Developers

I made this script below this text (Local-script, Inside of a button) where pressing It with a certain Item equipped will fire an event, currently, I tried doing so but It cannot fire It

Script:

local Player = game:GetService("Players").LocalPlayer
local Debounce = false

script.Parent.MouseButton1Click:Connect(function()
	if not Debounce then
		Debounce = true
		if Player.Backpack:WaitForChild("Crossbow") then
			Player.Backpack:WaitForChild("Crossbow").SpecialAbility1:FireServer()
			wait(3)
			Debounce = false
		end
	end
end)

1 comment

0

unrelated to the specific issue, but I did notice that the Debounce is placed incorrectly, and that could cause some issues eventually. The "Debounce = true" should be on the same level of the "Debounce = false". (i.e. you could put it inside the "if Player..." statement.)

1 answer

If a tool is "equipped" by a player it will be parented to their character rather than their backpack. So you just have to replace Player.Backpack with Player.Character.

(Also use FindFirstChild instead of WaitForChild, WaitForChild is used to wait for something to appear rather than to check if it exists.)

if Player.Character:FindFirstChild("Crossbow") then
	Player.Character.Crossbow.SpecialAbility1:FireServer()
	wait(3)
	Debounce = false
end

This discussion is preserved as it was. New answers, comments, and votes are closed.