Check if tool is equipped problem

I am trying to make it so that if someone has a tool equipped then a ProximityPrompt will be enabled/disabled

For some reason that I am unaware of this code doesn’t work

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

while task.wait() do
	if Player.Backpack:FindFirstChild("ZipTie") then
		if Character:FindFirstChild("ZipTie"):IsA("Tool") then
			script.Parent.Enabled = true
		else
			script.Parent.Enabled = false
		end
	end
end
``` script is LocalScript inside of the proximityprompt
1 Like

That might cause serious performance issues (depends on the players device), what if theres multiple prompts?

if Player.Backpack:FindFirstChild("ZipTie") then -- this is the problem!!
    if Character:FindFirstChild("ZipTie"):IsA("Tool") then -- also this!!!

if you equip the tool, it Parents into a character, so thats why.

if Player.Backpack:FindFirstChild("ZipTie") or Player.Character:FindFirstChild("ZipTie") then -- now fixd!!!

also try to avoid using while loops on situations like this,

try doing this instead, place it in the tool:

-- place me in the "ziptie" tool!!!!!

local Tool = script.Parent
local ProximityPrompt = nil -- put the proximity prompt path in here!!!!!

Tool.Equipped:Connect(function()
    ProximityPrompt.Enabled = true
    Unequip = Tool.Unequipped:Connect(function()
        ProximityPrompt.Enabled = false
        Unequip:Disconnect()
    end)
end)
1 Like

Avoid declaring globals (performs certain deoptimizations).

-- place me in the "ziptie" tool!!!!!

local Tool = script.Parent
local ProximityPrompt = nil -- put the proximity prompt path in here!!!!!

Tool.Equipped:Connect(function()
	ProximityPrompt.Enabled = true
end)

Tool.Unequipped:Connect(function()
	ProximityPrompt.Enabled = false
end)
1 Like