Getting a Players Tools

dunno what you guys are talking about you could’ve just done this

local function PartClick()
	--Whatever you wanna do when the part is clicked
end

local function OnToolAdded(Added)
	if Added:IsA("Tool") and Added.Name == "Name" then
		local Connection = ClickDetector.MouseClick:Connect(PartClick)
		Added.AncestryChanged:wait()
		Connection:Disconnect()
	end
end

local Connection = Character.ChildAdded:Connect(OnToolAdded)

local function OnRespawn(Character)
	Connection:Disconnect() --To prevent memory leaks incase many players leave and rejoin your game since this'll be a server script
	Connection = Character.ChildAdded:Connect(OnToolAdded)
end

local CharacterAdded = Player.CharacterAdded:Connect(OnRespawn) --to make the check work after player's character changes aka when they respawn

local Connection2
Connection2 = Player.AncestryChanged:Connect(function()
	Connection:Disconnect()
	Connection2:Disconnect()
	CharacterAdded:Disconnect()
end)

sorry for being about a year late

1 Like